Useful Linux Terminal Commands and Utils

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

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.

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

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 is for diagnosing DNS issues.
Its light weight, install it and play, dig -h for help.
Sample output

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.

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.