6 advanced linux commands you should know to be more productive

Almost every functionality in Linux is implemented as commands and command line utilities. If you work with command shells, then it is important that you have a working knowledge of many of these commands.

There are many commands that you will use regularly. Those are mostly simple commands that perform everyday tasks such as file editing, file management and search. I have written about a different set of commands that you might use only intermittently.

The commands in this post are by no means difficult but probably deal with tasks that are done much more infrequently. These commands are termed as advanced commands just because they are not performed very often.

chmod

This command is useful when you want to change the file permissions. The Linux file permissions and security are probably a little more advanced and involved than what I want to detail in this post. You can add or remove read, write and execute permissions for files and folder using this command.

bash$ chmod -Rv 755 /path/to/folder

The -R or –recursive command line option will change the file permissions recursively, traversing into each and every sub-folder.  The -v is the verbose option. You can change the permissions of a folder, a file or several files and folders all in a single command. As with most other Linux commands, you can use regular expressions to specify the files and folder. The command also takes multiple arguments for file and folder names.

bash$ chmod -Rv +w ~/temp/folderone/*.sh ~/temp/foldertwo/ ~/temp/file.txt

The above example adds the write permissions to several different files and folder as specified in the command line.

chown

This command can be used to change the ownership of a file or folder. This command is similar to the previous chmod command.  You can use this to change ownership of the files or folders. You will need either the root or superuser credentials in most situations.

bash$ chown -Rv tom:users ~/temp/folderone/*.sh ~/temp/foldertwo/ ~/temp/file.txt

The above examples shows how to transfer the ownership of several different files and folders recursively. You can use the -R or –recursive option if you want to change the ownership of subfolder and files inside the folder as well.

sort

This utility is useful when you need to sort the output of another command or a set of values. The sort command takes multiple files as argument and sorts the contents of the files. It writes the sorted concatenation of the files to the standard output by default.

bash$ sort -bdf file1.tx file2.txt file3.txt

The sort command has several different command line options. The -b or –ignore-leading-blanks option is useful when the lines are not evenly formatted and contains leading spaces. The -d or –dictionary-order option will consider only blanks and alpha-numeric characters when sorting. The -f or –ignore-case is useful when you want to do a case insensitive sort.

wc

When you need to count either the characters, the words or lines in a piece of text then wc is the easiest command to do it. The wc command print the newline, word and byte count for each specified file in the command line.

bash$ wc file1.txt file2.txt file3.txt

The wc command can take multiple files and regular expressions as command line arguments. You can use command line options to select which counts should be printed.

kill/killall

Once in a while you will run across a misbehaving application or process. The only way to terminate the process would be to kill it. The kill and killall command utilities allow you to kill or terminate processes from the command line.

bash$ killall firefox

The above command will kill all process (and thus applications) named firefox. You can also use the process id to terminate processes instead of the application name.

bash$ kill -9 2342

The above command will the process with id 2342 and all its child processes. You can specify multiple process ids as command line arguments.

tar/zip

Compressing, archiving and unarchiving files are still something you might have to do once in while. It is still one of the most efficient ways to transfer files between machines. tar and zip are the most commonly used commands to compress and archive files or folders. The command line option -c or –create will create a new archive.

bash$ tar -cfvz compressed.tar.gz folderone/* foldertwo/*

The above command will compress and archive the contents of folderone/ and foldertwo/ into a file named compressed.tar.gz. The other option is to use zip, which may or may not be available in all distros. An example of the zip command is shown below.

bash$ zip -9 -r compressed.zip folderone/ foldertwo/

The command line options to extract the archive is -x or –extract. In order to extract the archive created above, you will use the following command.

bash$ tar -xvfz compressed.tar.gz

shutdown

You will need to shutdown and reboot the system as well. It can come in handy if your desktop environment becomes unresponsive or if you are logged into the system remotely.

bash$ shutdown -r now

The above command will reboot the system immediately. The -r or -reboot option will reboot the system. If no options are used, then the system will shutdown. You can also specify the time when you want the shutdown to happen instead of using the now option.