Basic Linux Commands

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_physicalDesign

Change 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

$> cd .. ##This command takes you to one directory back.
$> cd /xyz/physical_design/timing #This command will take you to timing directory.
$> cd #If you are using only cd command then this will take you to home directory.
$> cd - ##This command will take you to previous directory you were in.

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

$> cp file1.tcl ../ ##This command will copy file1.tcl into previous directory.
$> cp file1.tcl file2.tcl ##This command will copy all the content of file1.tcl into file2.tcl
$> cp * ../ ##This command will copy all the files/directories present will be copied in one directory up.
$> cp -i file1.tcl file2.tcl
cp: overwrite `file2.tcl'?
##This command will ask for if you want to overwrite, type y then only it will overwrite.
$> cp -f file1.tcl file2.tcl ##If user permission is not there and still wanting to copy then use -f option.
$> cp -b file1.tcl file2.tcl ##This will create a backup file along with the regular file and below three files will get created.
file1.tcl file2.tcl file2.tcl~
$> cp -rf file1 .. ##This command will copy the file1 directory to one directory up. While copying directory we must need to use “-rf” command.

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.

$> mv file1.tcl .. ##This command will move the file1.tcl to on directory up, means file1.tcl will not be there in present directory.
$> mv file1.tcl file2.tcl ##This command will move the content of file1.tcl to file2.tcl and delete the file1.tcl at the same time.
$> mv -f file1.tcl .. ##This file will forcefully move the file1.tcl even if permission is denied.
$> mv -b file1.tcl file2.tcl ##This command will create a backup file along with destination file. Content will be file2.tcl file2.tcl~.
$> mv -n file1.tcl file2.tcl ##This command ensure that file will not be overwritten.

Remove files and directories

To remove/delete a file or directory we use rm/rm -rf command.

rm <fileName>
rm -rf <fileName>

Example

$> rm file1.tcl ##This command removes file1.tcl.
$> rm file1.tcl file2.tcl ##This command removes all the files written after rm.
$> rm -rf file1 ##This command will delete the directory file1.

Listing

Listing all the files present in the directory using command “ls”. Let’s look into few commands.

$> ls ##This command list all the files and directories present in present working directory.
$> ls -lrt ##This command list all the files along with permissions, username, group permission, file number months and Time, file name.
-rw-r----- 1 ivlsi pd_grp 76808 Nov 2 05:25 file1.tcl
$> ls -R ##This will list all the files in the sub-directories as well.
$> ls -a ##This will show all the hidden files present in the directory. Sometimes the files start with dot (.) are hidden in the
$> ls -al will list the files and directories with detailed information like the permissions, size, owner, etc.
$> ls -s ##This command will list file size
$> ls -S ##This command will short files by its size
$> ls -r ##This command will list in reverse order
$> ls -R ##This command list recursively directory tree.
$> ls -t ##This command shorts files by date and time

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.

$> gvim file1

In the empty file do, :wq!

Or we directly touch the file

$> touch file #It is used mostly when a run is over, and we need to touch the PASS 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.

$> chmod 777 #This gives file permission to read write and execute to Owner, Group and Other permissions.
$> chmod 775 #This gives file permission to read write and execute in owners and group but not for other permissions.
$> chmod 755 #This gives read write and execute permission to Owners but not for group and other permissions.
$> chmod 555 #This gives only read and execute permissions to owner, group and others.
$> chmod 743 #This gives read write and execute permissions to owner, group and others but read permission to group and write and execute permission to others.
$> chmod 043 #This gives no permission to owner but read permission to group and write and execute permission to others.

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.
$> sccj013110> sort file1.tcl
abc
abc
bca
cab
$> sort -u file1.tcl
abc
bca
cba
$> sort -c file1.tcl
sort: file1.tcl:4: disorder: abc

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.

Admin
Admin

Leave a Reply