Wednesday, 28 October 2015

Terminal Commands Crash Course: Part II

In this post, we will talk about some more basic terminal commands in Linux. If you haven't checked out the first part of this post, do check it out here.

 

Comments

Inside terminal, comments can be specified using the "#" symbol. Everything after this is considered as a comment and is not executed.
Ex: ls #This is the ls command, not cd!

The tilde

The home directory of a user is also represented by a tilde sign(~). So, "/home/niks/Downloads" is the same as"~/Downloads".

 

The history command


At any point, if you want to retype the previous command or just check what you've typed, just press the Up arrow key. Pressing the Up arrow key several times will display older commands. If you want to view all the commands we've typed till now, type history and press enter. Note that the size of this history is limited, and the number of commands stored by it can be changed by changing the HISTSIZE environment variable. (You can check it's value by typing: echo $HISTSIZE)

 

The mkdir command


This command allows us to create a new directory (folder). To make a folder named "foo" in the current folder, type:
mkdir foo

To make a folder named xyz inside /home/niks/Downloads folder, type:
mkdir /home/niks/Downloads/xyz

 

The rmdir command


This command removes an empty folder. To remove ~/foo, type:
rmdir ~/foo
If the folder is not empty, rmdir will not delete it. To delete a folder that contains some data, we will use another command.

Terminal Commands


The touch command


This command changes the timestamp of a file, as if it were modified jusst now. If the file does not exist, it creates an empty file by that name.

touch abc   #creates a new file named abc
ls -l       #shows the current timestamp of all files

Terminal Commands

 

touch abc   #updates the timestamp to current time
ls -l       #shows the changed timestamp for abc now

Terminal Commands



The rm command


This is perhaps one of the MOST DANGEROUS commands. This command deletes a file.
NOTE: Use it with caution. You will be responsible if you delete something important!!
rm abc  #this will remove the file named abc
To remove a non-empty folder, type:
rm -r foo

Terminal Commands


The mv command


This command is used to move a file from one foler to another. To move a file named abc from ~/ to ~/Wallpapers, type:
mv ~/abc ~/Wallpapers/

This command can also be used to rename files. To rename ~/Wallpapers/abc to ~/Wallpapers/xyz, type:
mv ~/Wallpapers/abc ~/Wallpapers/xyz

Terminal Commands


 

The cp command


This command is used to copy files. To copy xyz to pqr, type:
cp xyz pqr

If a file named pqr already exists, its contents are cleared and xyz is copied into it.

Terminal Commands

 

The cat command


This command, when used without options, shows the contents of a file on the standard output (terminal). To see the contents of abc, type:
cat abc

Terminal Commands

 

These commands should give you a basic idea to start with. Just practice them, but remember: DO NOT DELETE OR MOIFY ANY FILE THAT YOU DON'T KNOW ABOUT. You may end up with an unusable system if you do so. Now, if you are brave enough, just start practicing!

Also, if you are stuck at some point, or you forget some command or what option does what, just type man followed by the command. Ex: man ls will give you the manual page of ls, where you can look at all the options for ls and what they do. Also, if you want to know about the command that does a specific task (such as copying), type apropos copy (or apropos whatever_task_you_want_to_know_about). Always remember: A man is a man's best friend! ;)
Suggestions and queries are always welcome!

No comments:

Post a Comment