Linux terminal is a powerful tool that most Windows users do not use or know until they are forced to.
Case in point, about 2 years ago now I installed Ubuntu on my notebook and a year ago on my workstation.
The biggest reason is that mentioned in the first line of this post. The other being, well, windows is a bloated pile 🙂
The other is that programming on a machine running a Linux distro is a lot smoother.
No hacked together language installers that do who knows what to the registries on Windows.
Linux you just pop open the terminal and run the command to install whatever language you want, Python, RoR, Perl, PHP, etc..
Most of the time the site for the language gives you a copy and paste command.
There are hickups now and again, but once you learn how to debug them you are that much closer to understanding issues when they come up on live servers.
Anyway, I am going to run through some of my favourite commands and utilities.
This is a command that I aliased to lss and outputs file/folder permissions in alpha & numeric representation
stat -c ‘%A %a %n’ *
The output
drwxr-xr-x 755 Bookmarks
-rw——- 600 bookmarks.html
Pipes
Piping find into grep
You know how on Windows searches in the file explorer can take forever and a day.
In Linux, find is awesome, pipe it into grep for fine tuning.
Here we are searching for pear directories or files in the second line.
find usr -type d | grep -i PEAR
find usr -type f | grep -i PEAR
The d flag = directory
The f flag = “well” a file.
The -i flag = ignore case
This would be a good time to mention, that any command will usually have a help list and for the most part pretty good.
They are almost always available using the_command (hyphen)h or the_command (hyphen)(hyphen)help
grep has a pretty long list of options and you will see it used quit a bit in tutorials.
du –max-depth=1 -h /usr/
Is very useful when you need to find whats eating up your disk drive space.
Need to chmod “change permissions” for files recursively
find . -type f -exec chmod 664 {} \;
This command finds all files in the current directory and its sub-directories and executes chmod 664 on them.
Change the f to d and you change the all directory permissions.
netstat
I don’t remember if this is built in or if I installed it, but its great for identifying addresses, ports, processes and what apps are using them.
netstat -ntlp
Will output a list something like this but longer
1 2 3 4 |
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:11210 0.0.0.0:* LISTEN 3491/memcached tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1437/mysqld tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 3438/memcached |
top
Is a real time command that will show all of your resource info.
Load, processes, commands running, memory, RAM and disk, etc…
But and alternate utility that I like is htop.
Its more interactive allowing clicking with a mouse to sort columns and also shows a graph of your cores.
Press q to exit both top and htop.
On that note, some need to know simple commands.
Ctrl+c stops a run away command in its tracks.
q stops most commands usually interactive, like top or terminal editors like vi or other interactive tools.
clear clears the terminal window
Ctrl+Shift+v pastes from the clipboard
Ctrl+Shift+c copies the selected text.
up arrow brings up the last command that you ran
Ctrl+r brings up command search that allows you to search your command history as you type.
mv /var/tmp/sulog /var/adm/sulog move /var/tmp/sulog to /var/adm/sulog
cp -R copyDIR to DIR Copy recursive
rm Careful it deletes without remorse
rmdir Deletes directories, but you need to specify if you want it recursive.
There are a bunch more, like wget, tar, curl, etc…, but those are the ones I use the most, everyday.
Some more nice utilities,
dig
Dig is for diagnosing DNS issues.
Its light weight, install it and play, dig -h for help.
Sample output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
;; QUESTION SECTION: ;google.com. IN A ;; ANSWER SECTION: google.com. 117 IN A 74.125.225.40 google.com. 117 IN A 74.125.225.41 google.com. 117 IN A 74.125.225.46 google.com. 117 IN A 74.125.225.32 google.com. 117 IN A 74.125.225.33 google.com. 117 IN A 74.125.225.34 google.com. 117 IN A 74.125.225.35 google.com. 117 IN A 74.125.225.36 google.com. 117 IN A 74.125.225.37 google.com. 117 IN A 74.125.225.38 google.com. 117 IN A 74.125.225.39 ;; AUTHORITY SECTION: google.com. 31886 IN NS ns1.google.com. google.com. 31886 IN NS ns4.google.com. google.com. 31886 IN NS ns3.google.com. google.com. 31886 IN NS ns2.google.com. ;; Query time: 36 msec ;; SERVER: 207.230.202.28#53(207.230.202.28) ;; WHEN: Tue Mar 6 01:02:12 2012 ;; MSG SIZE rcvd: 276 |
For git fun tig
Interactive git browser for the terminal.
Shows, commits, messages, date/time, diff, merges, etc…
Another slick tool, ever need to post a directory tree?
tree utility will display a directory tree in the terminal.
So you can do this with nothing more than copy and paste.
1 2 3 4 5 6 7 8 9 10 |
. |-- data.txt `-- sub1 |-- another |-- file.txt `-- sub2 `-- sub3 |-- index.html |-- style.css `-- test.php |
I’m not even scraping the surface, but that’s all for now.
Play in the terminal, explore, and make it a habit or a main tool in your routine, and it will come natural.
Terminal is a very powerful tool and can make life with Linux a lot easier once your learn to utilise its resources.