Most of us are afraid of Linux commands, so here is my post to help those people. Although most of the things can be done using GUI now a days but knowing commands help a lot, specially when something goes wrong with your GUI. If you are in a fix about some command then there are two ways to get out of the problem.
- help : "$ command-name
". It shows the syntax and some basic explaination of the command.--help - man : "$ man command-name
" . It shows more details about the command.
- cd : Everything in Linux lies in a directory like thing called " / " or the root or the mount point of the file system. cd command is just like the cd used in windows i.e. it is used to navigate among the folders or directories. For example to go to a directory "/home/adimania" type $ cd /home/adimania and there you are.
- ls : To check the contents of a particular folder type $ ls . It will show the list of the files and folders present in the directory. Thats not all there is a lot more to ls than this. Use $ ls -al to view details about the file including the hidden ones!!! If you dont want to see the hidden files then simply do $ ls -l
- cat : This command is used to read the contents of a file or to write/append it. For example to read a file named adimania simply write $ cat adimania . Or to append it write $ cat > adimania . This will overwrite the file adimania. To append it you should write $ cat >> adimania. Two important point worth noting here are that your present working directory should be the one where the file to be read/append is present and that you cannot completely edit the file by cat command. Most probably you will end up overwriting it, so use cat for reading and avoid writing with cat command
- pwd : This command simply tells us about the present working dirctory of the user firing it. For example user adimania upon login will go to /home/adimania by default. so immidiately on login if you write $ pwd then output will be /home/adimania .
- mkdir : This command is used to create directories provided you have permission to do it. For example if you want to create a directory on /home/adimania you can do so by writing either $ mkdir /home/adimania/aditya or $ mkdir aditya . Can you tell me the difference? .... First command will run from anywhere, you just need the permission, while the second will work only if you are present in /home/adimania. In other words former is the absolute path and latter is the relative path.
- rmdir : This command is used to remove or delete an empty directory. Mind it, the directory should be empty. To delete aditya created by previous command you should type $ rmdir aditya. If the directory is not empty then an error message will flash.
- rm : This command will come to rescue when the directory is not empty. rm command basically deletes the files present in the directory. If there exists a file called friends in aditya directory then you should first delete the file friends by writing $ rm friends or you can also write $ rm /home/adimania/aditya/friends. You can also delete all the files in one go by writing $ rm *. The rm command can be used to delete a non empty folder just by writing $ rm -r /home/adimania/aditya. Here -r stands for recursively.
- mv : Ths command is used for moving a file or a folder from one place to another. To execute this command you need to write $ mv /home/adimania /home/adimania/aditya. Here first path is the source from which the folder/file is to be moved and the second one is destination where the moved file will ultimately reach. You can also use this command to rename any file or folder.
- cp : This command is used to copy a file or a folder from one place to another. The command format is similar to mv command. To execute this command you need to write $ cp /home/adimania /home/adimania/aditya. Here first path is the source from which the folder/file is to be copied and the second one is destination where the copied file will ultimately reach.
- touch : This command changes the time stamp of the files. If the file does not exist it will create an empty file. It is typed as $ touch aditya.
- echo : This command displays a text or a value contained in a variable. It can also be used to to write the output in a file by using '>' or to append use '>>'. For example $ echo hello will give output as hello. To write "Hi how are u?" in a file hello.txt you can execute $ echo Hi how are u? > hello.txt and you will get desired result. Most wide use of echo command is in getting the values of variables. For example to know the value stored in PATH environmental variable simply write $ echo $PATH.
There's a typo on your blog post.
ReplyDeleteIt reads:
man : "$ command-name man ". It shows more details about the command.
It should read:
man : "$ man command-name ". It shows more details about the command.
Best regards,
Hey Bruno,
ReplyDeleteThanks for pointing it out. I have updated it.