Linux comes with many command line tools out of the box and these are the first 10 you should know.
man -- man by itself does not do anything. man is the interface to othe on-line reference manuals. Proper usage is man followed by the name of the command line tool name.
man pwd will call up the reference manual for the pwd command which will print the current/working directory in the terminal. Which brings us to the first command line tool you should know.
Enough with the preview, now we go to the first 10 command line tools you should know.
- pwd -- print name of current/working directory. This command is good to establish your current working directory. If you are not sure pwd will show you.
- ls -- list directory contents. Once you know which directory you are currently in, it is good to know the contents of the directory. ls will do this for you. ls has many useful options like -l or -a to modify the output of ls. The -a option will output hidden files and subdirectories of you current directory. The -l option will give you a long list format of the files and subdirectories. You may also combine options, for example
ls -lawill give you a long listing format including hidden directories and files. For more options use
- mkdir -- make directories. This command will create a directory in the current directory. For example, if you wish to create a bin directory in your home directory then
mkdir binwill create a directory in your home directory. If you need to create two or more directories at the same level you only need to separate the directory names by a space like so
mkdir bin java html videos. This will create the four directories bin, java, html and videos in the current directory.
- cd -- change directory. This command along with a path will change your current working directory of the given path.
cd /tmpwill change the working directory to the /tmp directory.
- cp -- copy files and directories. If you wish to copy files locally from one location to another this is the command. Using thiis command, you list the source file or directory and the destination to which it should be copied.
cp /home/me/mytextfile.txt /home/me/bin/will copy the file mytextfile.txt to the directory /home/me/bin/
- mv -- move or rename files and directories. If you want to move or rename a file or directory instead of copying it, this is your command.
mv /home/me/mytextfile.txt /home/me/bin/will move your file from /home/me/ to /home/me/bin/ and unlike the cp command the mytextfile.txt will no longer be found in the /home/me/ directory.
- rm -- remove files or directories. This can be a very dangerous command. Depending upon your system setup, you may be asked if you really want to remove the file and give you a chance or it will just execute the command and the file will be gone and very difficult to recover. Use care when removing files and directories.
rm mytextfile.txtwill remove the file if it is in your current working directory or if the file does not exist, an error message will be displayed.
- less -- allows you to read long text files with pagination. This command will display one screen of text an stop. less also allow you to paginate forwards and backwards unlike more will only allows to to paginate forward. As they say, less is more.
less mytextfile.txtwill print up to one screen of content and stop, waiting for you to continue. If the file contains less than on screen of text, the entire contents of the file will be printed to the screen and wait until you press "q" to exit the program.
- top -- displays Linux processes. top displays dynamic real time information of a running system. If your system is running slow or you are just interested in seeing what is running on your system to to top. top is very flexible and has many features. Use
man topto discover more.
- df -- report file system disk space usage. df will show you how much space is used and free in each filesystem. df alone will show the output in kilobytes which is very accurate but for your comfort you may want to add a -h option for human readable
df -hwhich will append a K, M or G for Kilobyte, Megabyte or Gigabyte which is much easier to read, especially with Terabyte Storage as the standard.
These ten command line programs are a good start in file management, reading text files and proofing a few system parameters for performance or disk usage. Have fun, experiment and don't forget to read the man pages to find out even more about these commands.