linux_commands
linux_commands
About Linux OS
Ubuntu is arguably one of the most highly regarded and widely used Linux distributions available today.
Praised both for its ease of use and reliability, Ubuntu also has a loyal following of Linux users and an
active community of developers. The source code that makes up the Ubuntu distribution originates from a
highly regarded Linux distribution known as Debian created by Ian Murdoch. If you are new to Linux, or
already use Linux and want to try a different Linux distribution it is unlikely you will find a better option
than Ubuntu.
If you are running Ubuntu with the GNOME desktop and need to access a command-prompt you will
need to open a terminal window. This can be achieved by right-clicking on the desktop background (or
any folder/file location in your computer) and selecting the Open Terminal menu option. A terminal
window may also be opened within the GNOME desktop using the Ctrl-Alt-T keyboard accelerator. In
this tutorial, it is assumed that the Linux OS is already installed in your computer/laptop.
2. Important Commands in Linux OS
When processing SAR datasets, one has to know the following commands for frequent use –
To remove a directory
$ rmdir # removes empty directories in current directory
$ rm –r ~/<directory name> # remove a directory recursively
$ rm –rf ~/<directory name> # remove a directory recursively without
requiring confirmation
To locate a file
$ locate –i school # search a file which contains the word ‘school’
anywhere
$ locate –i school*note # search a file which contains word ‘school’
and ‘note’ anywhere
$ find .-name notes.txt # search a file notes.txt in current directory
To search a word in a file
$ grep blue notepad.txt #searches a word blue in notepad.txt file
To get a report on the system’s disk space usage
$ df # report in % and KBs
$ df –m # report in Megabytes
There may come a time that you want to remove some or all the commands in your history file.
If you want to delete a particular command
$ history -d <line number>
$ history –d 16 45 # Deletes all list entries from 16 to 45
$ history –d -8 # Deletes only the last eight commands
Zip and unzip command
$ sudo apt-get install zip # install zip (if not)
$ sudo apt-get install unzip # install unzip
$ zip options zip_file file1 file2 .. # zip many files into single
$ zip –u zip_file filex # add a file in existing zip file
$ zip –m zip_file file1 file 2 # deletes original files after zipping
$ zip -e zip_file file1 file2.. # create password protected zipfile
$ unzip options filename.zip # unzip a file
$ unzip filename.zip –d ~/../ # unzip in a particular directory
$ unzip ‘*.zip’ # unzip multiple zip files
$ unzip -P <password> zip_file # unzip password protected zipfile
Options:
--delete : delete from the archive (not on mag tapes!)
-r, --append : append files to the end of an archive
-t, --list : list the contents of an archive
--test-label : test the archive volume label and exit
-u, --update : only append files newer than copy in archive
-x, --extract, --get : extract files from an archive
-c, --create : create a tar file
-C, --directory==DIR : change to directory DIR
-f, --file=ARCHIVE : use archive file or device ARCHIVE
-j, --bzip2 : filter the archive through bzip2
-J, --xz : filter the archive through xz
-p, --preserve-permissions : extract information about file
permissions
-v, --verbose : verbosely list files processed
-z, --gzip : filter the archive through gzip
Change read, write and execute permissions of a file
$ chmod ugo <file address> # to give r, w and x permissions
Where
o u=r+w+x, g=r+w+x, o=r+w+x; Here u, g and o are in octal number system
o u-user, g=group, o=organization, r=read, w=write, x=execute
o Octal Notation: 744 means; u=7, g=4, o=4
o Number r=4 gives read permission, w=2 gives write permission, x=1 gives execute
permission and 0 gives no permission
o Thus 777 gives read, write and execute permission to user, group of users and organization.
$ chmod 777 /home/iirs/Project
$ chmod 461 /home/iirs/Project #gives read permission to user, read and write
permission to group, and execute permission to organization
To check the current jobs and their statuses
$ jobs # jobs and their status in current directory
To terminate an unresponsive program manually
$ SIGTERM(15) # requests a program to stop running
$ SIGKILL(9) # forces programs to stop immediately. Unsaved progress
will be lost.
To check your internet connectivity status to a server
$ ping google.com
$ ping iirs.gov.in
Whoami, Uname, top commands
$ whoami # see root user
$ uname # know your machine name, operating system, kernel, and
so on.
$ uname –r # show system information
$ top # display a list of running processes and usage of CPU
by each process
$ last reboot # show system reboot history
$ timedatectl # query and change the system clock
$ date # show the date and local time
$ uptime # show how long the system has been running,
including load average
Reissue the last command (Note that the previous command is listed and performed)
$ !! or $!-1
Execute the last command that contains a particular word (not necessarily at the line begin)
$ !?man? or $ !?pwd?
To find out where a particular executable resides on the file system
$ which ls
$ which history
OR download .tar or zip file and untar or unzip file, cd to that untar or unzip file, and run
$ sudo ./configure –prefix=<installation directory>; make; make install
$ sudo ./install.sh -p <installation directory>
1
GeoAI for Urban Sensing, Summer School in Gammarth-Tunis, Tunisia
Technical Session (T2) on SAR and InSAR for Urban Cities