File Manipulation Commands for Linux

0
10

The command line tool in Linux probably is its most versatile and powerful tool. There is a discrete core of basic commands that can make the entire OS your playground in a matter of time. This article will deal with file manipulation tools available through the Linux command line environment.

Touch is a command used to create a new, empty file. It can also be used to change the modification date and time of a current existing file, to the current date and time.

The mv command is used to move a file to another file directory of your choice. This command can also be used to change a file's name. The latter can be done by simply entering mv followed by the existing file name, which in turn should be followed by the desired file name. The cp command can be used to make a copy of a file, and put it at the address / directory that you choose. When you make an erroneous extra copy, or just have junk files to delete, you can use therm command. It can remove a file that you do not need any longer.

To create a new file directory altogether, use mkdir (make directory). Use cd to navigate to the place in which you want to create the new directory, and enter mkdir followed by your desired directory name. You can also remove an entire directory, if needed, with the rmdir (remove directory) command.

This brings us to despite the most important command yet – the grep command. This command is a useful search tool that will look for any pattern / string that you specify. If grep does find a match to your search string, it will return the results, along with the line line (s) in which they were found. Quotation marks are a smart shortcut here, especially when you are looking for a very specific pattern. They indicate that grep should search for exactly what you specify, in the same order and style.

The head and tail commands can be used to display the first ten and last 10 (respectively) lines of a file you choose. They may seem to have a limited scope, but you can use them as quick shortcuts to inspect files!

The wc command does a complete word count of the file you choose. There are modifying switches available that let you choose whether you want to see the number of lines ( -l ), words ( -w ) or characters ( -c ). Not specifying any of these switches leads to the default result of all three being returned.

Wildcards are versatile shortcuts designed to match patterns. An asterisk (*) can match any number of characters, from none, to multiple. A question mark, on the other hand, matches just a single character. You can specify choices too, by putting two characters, for instance, in square brackets. To change the choice of an 'either-or' to a 'neither-nor', all you need to do is add an exclamation mark (!) In front of the two choices. Moreover, these square brackets can be used to specify a range too, by simply putting a hyphen / dash in between them.

The commands described in this article are a handy way to manage files and directories in the Linux environment, all through the command-line tool. Some practice is all it takes for you to be raaring to go!

Learning to know more? Have a look here

Source

Leave a Reply