List of Basic Linux Commands#
Create directory
Mkdir is the command which we use to create directory, mkdir is short form of make directory. The command structure is as per below.
mkdir <directory_name>Example
mkdir ivlsi_physicalDesignChange Directory
Change directory is command which helps us to switch one directory to another. cd is the short form of change directory. The command structure is as per below.
cd <directory_name>Example
Copy Files and directories
To copy file or directory we use the command “cp”. cp is short form of copy. The command structure is as per below.
cp <file name/ directory name to be copied> <location to be copied>Example
Move files and directory
To move a file or directory we need to use the command “mv”. Using cp we will not delete the file/directory which we are copying but if we use mv then we are deleting it.
Remove files and directories
To remove/delete a file or directory we use rm/rm -rf command.
rm <fileName> rm -rf <fileName>Example
Listing
Listing all the files present in the directory using command “ls”. Let’s look into few commands.
pwd
Present working directory, this command says that currently which directory you are into.
Echo
Echo command is used to display text or argument, passed in argument.
Touch command
There are few times we just need a file with 0KB (Blank file). We can create an empty file in gvim as well.
In the empty file do, :wq!
Or we directly touch the file
CAT command
CAT is short from of concatenate which helps to display the content of file in terminal or merge 2 or more files. Let’s see the below examples.
#1. Content of file1.tcl is as per below.
abc
123
def
456
$> cat file1.tcl
abc
123
def
456
#2. Suppose we need to merge two files; we can do this by using cat commands. Now cat command will paste first file then second file. If there are more files then it will follow the same same sequence as it will paste first file then second file then third file then fourth and so on.
File1.tcl File2.tcl
abc cba
123 321
def fed
456 654
$> cat File1.tcl File2.tcl
abc
123
def
456
cba
321
fed
654
Note: If one wants to redirect this in one file then use greater than (>). Let’s see the example below.
$> cat File1.tcl File2.tcl > File3.tcl
Once you use the above command, the File3.tcl content is as per below.
abc
123
def
456
cba
321
fed
654
#3. If you want to print the content of file with the line numbers, then one can use below command.
$> cat File1.tcl
1 abc
2 123
3 def
4 456
#4. If you don’t want to open VIM and write into a file using CAT then use below method.
$> cat <The content of file which one wants to write> > file1.tcl
For EG.
$> cat abc 123 def 456 > file1.tcl
The content of the file1.tcl is abc 123 def 456.
Special case
Suppose we want to cat two line, where lines should copy parallelly, we use Paste command
File1.tcl File2.tcl
abc cba
123 321
def fed
456 654
$> paste File1.tcl File2.tcl
abc cba
123 321
def fed
456 654
Absolute path or real path
If one wants to find the absolute path of a file, then use the command “abspath” or “realpath” with the file.
abspath file1.tcl -> This will print the full path of the file1.tcl
realpath file1.tcl -> This will print the full path of the file1.tcl
Disk Utility Command
#1. df -h ## To check the memory of the total disk area used and available. If you run this command you can get below information’s like Filesystem Size Used Avalable Use% and mounted on.
Filesystem Size Used Avail Use% Mounted on
If wants to check this for current directory then use dot (.) command along with df -h,
#2. If you want to see the directories/files how much memory is getting consumed, then use below command. This will write the memory then file/directory name. Where M is megabyte and K is kilobyte.
du -sh *
For Eg.
1.7M File1.tcl
522K File2.tcl
Modes of Files/Directories access
There are different modes of files to handle Read (R), Write (W), Execution (X).
Read (r) : This allows file to read only of the content present.
Write (w) : This allows file to write/edit in the file. If this is a directory, then user can add/delete the files present.
Execution (x) : This allows file to run if this is a script file.
To represent the permission mode of files/directories we use Octal number representation where all the number from 0-7 having different values, which will be used with chmod command in linux.
| Octal Number | Permissions |
Linux Representation
|
| 0 | No Permission | --- |
| 1 | Execute | --x |
| 2 | Write | -w- |
| 3 | Execute (1) and Write (2) [1+2=3] | -wx |
| 4 | Read | r-- |
| 5 | Read (4) and Execute (1) [4+1=5] | r-x |
| 6 | Read (4) and Write (2) [4+2=6] | rw- |
| 7 | All Permission (Read (4), Write (2), Execute (1)) [4+2+1=7] | rwx |
Let’s understand more with the commands now.
[-][-][-] -> This is the way where we change file permission.
[-] -> The first one is Owner Permissions.
[-] -> The second is Group Permissions.
[-] -> The third one is Other Permissions.
You can change owner of the file using chown command.
chown user filelist
Eg. chown Hari File1.tcl
You can change the group permission of the file using chgrp command.
chgrp -R <Group Name> <Directory Name>
chgrp -R timing_grp timingReports
User details and change
If you want to check the username using the terminal, then use “whoami” command.
If you want to change the user then use “su” command, short form of switch user is “su”.
su <user_name>
eg. su ivlsi_2 ##Now this will look for password of ivlsi_2 user.
If one wants to check the groups, you are part of then use the command “groups”.
Sorting
There can be many lines in a file which is repetitive, to avoid repletion in a file we use the command “sort”.
$> cat file1.tcl
abc
bca
cab
abc
Eg.Jobs information’s and kill:
If you want to see the running jobs, then use the command “jobs”. To kill the jobs one can use “kill” command flowed by job ID.
