Back when I was in the corporate world one of my co-workers used to call me “DOS boss”, I guess because I was far more comfortable working in dos then working with Windows to accomplish system functions. Possibly because of my early days when I would modify the batch and config files of my BBS, or maybe it goes back to my roots when I would type programs from magazines into my VIC 20 (and save them on cassette tape!) so I could play games. By the way, here’s a vic 20 tip: R shift U is a shortcut for Run.
Anyway, these days I work mostly on a mac but I have cause to remote it our linux web servers quite often. I’m definitely no expert in this world, but I can usually accomplish what I need to get done.
Here’s some of the commands I frequently use.
ls (like dir on a pc .. thats a lowercase L, not a one)
ls -l (same, but a more useful format .. thats a lowercase L, not a one)
ls -lrt (ls sorted by most recently edited, which will be at the bottom)
du -k * | sort -nr | cut -f2 | xargs -d ‘\n’ du -sh (lists the directories of the current directory sorted largest to smallest)
cat (like type in dos, it displays the contents of a file)
cat | more (displays contents one screen at a time)
tail -50 (displays the last 50 lines of a file. Handy if you want to see the last few lines of a log. Change the number to see more or less)
find -name ‘*.php’ (finds any file that ends with .php in the directory your are currently in or any of its subdirectories)
find -name “*.php” -exec grep -H “hello” {} \; (finds any file that ends with .php in the directory your are currently in or any of its subdirectories that contains the word hello)
find -mtime -1 (finds any file in the directory you are currently in or any of its subdirectories that has been modified in the last day. Change the number to see more days)
find -name “*.php” -mtime -1 (find any file that ends with php that has been modified in the last day in the current directory or subs)
grep hello * (search for files in the current folder that contain the word hello)
grep -R hello * (search for files in the current folder and subdirectories that contain the word hello)
grep -Rl hello * (same as above, but just lists the name of the files, rather then showing the occurrence of the word in the file)
mail -s ‘some file’ simon@yourwebsite.com < ./someotherfile.txt (sends email from the console this example sendsthe contents of a file with subject line ‘some file’ to the email address specified)
tar -Rcp –gzip –file=backupSite.tar.gz directorytobearchived (archives a folder structure, including all subdiretories, into a gzip file)
untar -xvzf somefile.tar.gz (unarchives a folder structure – restoring all subdirectories)
Editors
nano
vi
vim
.. use them like this: nano somefile.txt to edit the file you need
There you have them. Those commands, as well as googling for variations of them, allow me to do almost anything I need to in the console.
Simon
sort -nrcut -f2xargs -d ‘n’ du -sh (lists the directories of the current directory sorted largest to smallest)
cat (like type in dos, it displays the contents of a file)catmore (displays contents one screen at a time)
tail -50 (displays the last 50 lines of a file. Handy if you want to see the last few lines of a log. Change the number to see more or less)
find -name ‘*.php’ (finds any file that ends with .php in the directory your are currently in or any of its subdirectories)find -name “*.php” -exec grep -H “hello” {} ; (finds any file that ends with .php in the directory your are currently in or any of its subdirectories that contains the word hello)find -mtime -1 (finds any file in the directory you are currently in or any of its subdirectories that has been modified in the last day. Change the number to see more days)find -name “*.php” -mtime -1 (find any file that ends with php that has been modified in the last day in the current directory or subs)
grep hello * (search for files in the current folder that contain the word hello)grep -R hello * (search for files in the current folder and subdirectories that contain the word hello)grep -Rl hello * (same as above, but just lists the name of the files, rather then showing the occurrence of the word in the file)
mail -s ‘some file’ simon@yourwebsite.com < ./someotherfile.txt (sends email from the console this example sendsthe contents of a file with subject line ‘some file’ to the email address specified)
tar -Rcp –gzip –file=backupSite.tar.gz directorytobearchived (archives a folder structure, including all subdiretories, into a gzip file)untar -xvzf somefile.tar.gz (unarchives a folder structure – restoring all subdirectories)
Editors
nanovivim
.. use them like this: nano somefile.txt to edit the file you need
There you have them. Those commands, as well as googling for variations of them, allow me to do almost anything I need to in the console.
Simon