Hi, If you want to work in Linux, you must know the commands. But If you are still a beginner, It’s OK. No need to be confuse. It’s easy. This article will cover basic commands that you need to work with Linux. You have to gain this little by little. So we will start.
When you logged into your account, you can see a ‘$’ mark. That’s called as a prompt. It comes when you are logged in as a normal user. If you are in root account, the prompt will be ‘#’. It’s a sign of identifying where are you.
Once you logged in, you will go to your home directory (directory is like a folder in windows), like below.
[[email protected] ~]$
student – Your account name
localhost – Your hostname
~ – Your current directory ( your present folder )
$ – Your prompt
Hereafter, we will learn simple basic commands that we need in day today life.
1) pwd : print working directory
[[email protected] ~]$ pwd
It shows where are you now. It displays the directory currently you are.
2) ls : list files
In a linux command, we can see a format like below,
command [options] [arguments]
options are used to customize our command to have a different output with more details. arguments are to which elements the command is affecting for. we can use commands with or without options or arguments. Keep it remind. It depends on the command. Let’s have a look the below commands with options and arguments.
[[email protected] ~]$ ls
It lists files in your present directory
-l ( ls -l ) : long listing of files. This lists more details about the files and directories under present working directory. This shows the user and file permissions, file modified dates, file sizes with file name.
-a ( ls -a ) : list all the files including hidden files inside of the present working directory. ls command lists only files without hidden.
-d ( ls -ld ) : -d options is used to show the details of the present working directory. ls -l command shows details of the files under present working directory. But -d options shows working directory information. Use ls -ld, not ls -d. Because ls -d doesn’t show what you expect. Try it. Then understand what is the output of commands.
-R ( ls -lR) : -R is recursive option. If you want to list files of the directories to the end of the tree from the current directory. ls -lR displays all the files with brief details of all the files in every directory with it’s directory name.
-h ( ls -lh ) : -h is used to show the file sizes in human readable format. It will display the sizes in KB or MB or GB.
-r ( ls -lr ) : -r option is used to reverse the output. Simply it shows the reverse of the original list of files inside of the current directory.
-t ( ls -lt ) : -t is used to sort the files in time modified. ls -lrt is used to reverse the output.
-S ( ls -lS ) : used to sort the files in size.
-i ( ls -li ) : -i is used to display the details of the file’s inodes. inodes is an entry which stores information about a file. Like file type, permissions, user id, group id, sizes, time stamp.
–help ( ls –help ) : –help is a command that you need to learn in first stages. Because with –help options you can learn about the commands. with help you can learn many more thing than here i have mentioned. So as a beginner, i prefer you to read those help pages. Because i did the same thing.
*** As arguments, you can give whatever location( path ) you need. It’s not just only your current location.
eg – ls -ld /tmp , ls -l /home/student/Documents, ls /home
3) cd : change directory
[[email protected] ~]$ cd /home/student/Videos
This command changes my present directory to /home/student/Videos. Simpy it commands to go to that mentioned directory. In windows when you click the button and goes to the required place. But in linux you need to run the command and do it.
cd /home/student : Go to directory /home/student
cd /var/log : Go to directory /var/log
cd – : Go to my previous location where i was ( keep ‘cd -‘ in your remind, it’s very useful)
cd /home : Go to directory /home
cd .. : Go to one step back from the current directory ( means go to the backward directory )
cd . : Go to the present directory ( simply doesn’t go anywhere )
cd ~ : Go to home directory. simply if i am in student account, cd ~ command will go to /home/student directory
cd ../.. : Go backward twice. Means go two directories back. If i am now in /home/student directory, this command will go to / directory.
cd : only cd command will go to it’s home folder itself. its like cd ~ command.
4) vim – Create a text file
[[email protected] ~]$ vim mytextfile.txt
This command will create a text file with name “mytextfile.txt” in the present directory. Vim command opened it’s text editor when you run the command. You have to type what ever you want to write and saved it and quit from the editor.
To save the content you wrote, you have to do something more.
To save : press ESC and ‘:w’ in keyboard [ esc + :w ]
To save and quit : press ESC and ‘:wq’ [ esc + :wq ]
To quite without saving : press ESC and ‘:q’ [ esc + :q ]
If you get an error when quit without saving or quit with saving, do force quit. its, ESC + :q! or
ESC + :wq! ( ! is using for forcing )
5) touch – touch command
[[email protected] ~]$ touch mytextfile2.txt
This command will also will create the text file with the name mytextfile2.txt and it will not open at that time like vim. you can edit the file later.
6) cat – cat command
[[email protected] ~]$ cat mytextfile.txt
cat command is used to view a file.
7) less – less command
[[email protected] ~]$ less mytextfile2.txt
less command is also used to view a file. But it is different from cat. Because if its a 1000 word file. It we use cat command we can see only the end part of the file. But less command gives us the feature for scrolling up and down through the file. Because of that we can see the complete file even if the file is larger too much.
8) more – more command
[[email protected] ~] cat mytextfile.txt | more
This is also doing the same thing in less. You can see “|”. That is pipeline. With pipeline we can send the output of the left side to the right side as an input. So cat command will view the file and more command will use to view it like less command.