24 Helpful UNIX Commands Every Developer Should Know- 7 mins
Essential UNIX Commands
Learning the basic Unix commands is as a very useful skill in the daily life of a Developer. Being confident to use the command line as a tool to deploy, maintain and debug applications is a big chance to dive into the mystic area of DevOps.
In UNIX, everting is a file. And every file has a manual that describes it. The man command allows you to retrieve the information in the manual and display it as text output on your screen. Using the man command on itself, will give you the manual of the man command.
The pwd or print working directory command will show you the full pathname of your current working directory.
The ls or list comes with a dozens of options. The most common ones are:
- -l to show information about the file e.g. file name, size, owner, permission etc
- -a shows hidden files
- -lh shows sizes in human readable format.
- -F will add the ‘/’ Character at the end each directory.
- -r option display files and directories in reverse order.
- -ltr will shows latest modification file or directory date as last.
- -lS displays file size in order, will display big in size first.
A shorter way for ls -l is the ll command. Depending on the OS version you use, ll is either aliased to ls -alF or ls -l.
The cd or change directory command will change your current working directory.
You can move up one directory level by simple using the cd.. command.
The cd - command is the command-line equivalent of the back button which takes you to the previous directory you were in.
The mv or move command allows you to move files or directories.
The rm -rf or remove recursive force command, where -r recursive deletion of a directory and -f is “–force” which overrides some sanity checks and prompting, allows you to delete a directory with all of its subdirectories and files in it.
The df or dirsk free command displays the amount of available disk space being used by file systems. It also reports the device name, total blocks, total disk space, used disk space, and mount points on a file system. Most common option for this command are:
- -T display file system type.
- -t display certain file system types only.
- -x exclude certain file system types.
The df command also provides an option to display files sizes in human readable formats by using the option -h.
To get the total disk usage size of an directory use the option - as follows.
The tail command is very useful while debugging. Instead of limiting by number of lines this will limit by the number of bytes passed to the -c option.
It also allows you to “follow” or show e.g log file entries in real-time which simplifies the bug hunt. If you want to see and follow incoming requests, just add the -f option.
The mkdir or make directory command allows you to create your folder structure.
The !! command allows you to repeat your last command.
The most useful in the form: to run last command with your admin rights. This can be achieved by the sudo command which stands for “superuser do”. It prompts you for your personal password.
The !$ command take the last word of the previous line.
Valuable UNIX Commands
We can use the mkdir command also to create nested folders via command line.
The touch command allows you to create files. You can also create files into one of the folders we’ve created one line above.
Another very helpful command is ‘^string^string2’ which takes the last command, replaces string with string2 and executes it.
The awk or short for Aho, Weinberger, and Kernighan, is an interpreted programming language which focuses on processing text.
The most common options are:
- -Ffs Sets the input field separator to the regular expression fs.
- -v var=value Assigns the value to the variable var before executing the awk program.
- -f progfile Specify progfile which contains the awk program to be executed.
- file… A file to be processed by the specified awk program.
The grep or global regular expression print command processes text line by line (file or standard input) and prints any lines which match a specified pattern. By default, grep prints the matching lines.
Lets combine some unix commands to get a list of all used commands sorted by the quantity of usage. We can use the command called pipe l that allows us to pass the output of one commands to another one.
Most of the above UNIX commands come with a variation of options. To master UNIX commands is a very important skill in the daily life of a Developer. o simplify shipping, debugging and maintaining your applications wandering in application infrastructures.