0% found this document useful (0 votes)
3 views9 pages

linux_commands

The document provides an overview of the Linux operating system, specifically focusing on the Ubuntu distribution, known for its user-friendliness and reliability. It details essential Linux commands for various tasks such as navigating directories, managing files, and checking system status, along with shortcuts and command-line options. Additionally, it includes instructions for running multiple commands and obtaining help for specific commands.

Uploaded by

Vis hal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

linux_commands

The document provides an overview of the Linux operating system, specifically focusing on the Ubuntu distribution, known for its user-friendliness and reliability. It details essential Linux commands for various tasks such as navigating directories, managing files, and checking system status, along with shortcuts and command-line options. Additionally, it includes instructions for running multiple commands and obtaining help for specific commands.

Uploaded by

Vis hal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

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 –

2.1 Common Useful Commands (at Prompt)


 To see the present/current working directory
$ pwd
 To change the current working directory
$ cd /../../../<directory name>
 To change the working directory as a shortcut in advance
$ HOME_DIR=$/home/iirs/dir1/dir2/ #fixes directory with short name
$ cd $HOME_DIR # changes the desired directory as working
directory
 Few arguments on cd command
$ cd .. # moves one directory up
$ cd ~ # directly come to root directory
$ cd ../../ # goes two step back
$ cd- # moves into previous directory
 To know about all folders and files under present working directory
$ ls # shows all files and folders in current directory
$ ls –1 # shows all files and folders of current directory
$ ls –R # lists all the files in the sub-directories as well
$ ls –a # shows the hidden files
$ ls –l # lists the files and directories with detailed
information like the permissions, size, owner, etc.
$ ls –al # lists the files and directories with detailed
information like the permissions, size, owner, etc. including hidden
files
 Use of cat and touch command
$ cat > filename # creates a new file
$ touch filename # creates a new file
$ cat file1 file2>file3 # joins file1 and file2 and store output in a
new file3
$ cat filename | tr a-z A-Z # converts a file to upper or lower case
use
 To copy file from the current directory to a different directory
$ cp filename.extension ~/destination Directory/
$ cp file1 file2 # copy the contents of the first file to the second
file
$ cp –r file1/directory1 ~/directory2 # recursively copy the contents
of the first directory into the second directory

 To move /rename file from the current directory to a different directory


$ mv filename.extension ~/destination Directory/
$ mv file1 file2 # renames a file1 to file2
 To make a new directory
$ mkdir <directoryname> # creates new directory in current directory
$ mkdir <newdirectory> /home/anotherdirectory/ # creates new
directory in another existing directory

 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

 To check how much space a file or a directory has (File size)


$ du filename # check disk space of a file or directory
$ du ~/filename # file size in KBs in a given directory
$ du –sh ~/filename # File or Folder size of a given directory
$ du –ah ~/filename # shows disk space for all files/directory

 To view the head and tail of a text file


$ head –n filename.ext # shows first ten lines
$ head –n 5 filename.ext # shows first five lines
$ tail –n filename.ext # shows last ten lines
$ tail –n 5 filename.ext # shows last five lines

 History Command (to review the commands you’ve entered before)


$ history # To see the command line history in the shell
$ history | grep <Any Term used in the past> # To search a specific
term using history and grep
$ history | less # If you wish to view the history of one page
$ history | tail # Views just the last ten commands
$ history 25 # Views the last 25 commands
$ history -w ~/history.txt # save bash history manually to a file
$ history –c # Clear the entire contents of the history file
$ .bash_history # The history file is stored in a file that you can
modify, as well. Bash shell users find it in their home directory.

 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 for Zipping:


-u : Updates the file in the zip archive
-d : Deletes the file from the zip archive
-m : Deletes original/main files after zipping
-x : Exclude files when we are going to create the zip
-r : Recursively zip the files inside it and then folders inside it
-v : Verbose mode option we will print diagnostic version information

 Tar command (Many uses)


$ tar <option(s)> <file(s)> # general command
$ tar –xvf filename.tar # to untar/extract a tar file (~unzip)
$ tar –cvf mytarfile.tar ~/file1 ~/file2 ~/file3 # creates a
mytarfile.tar in current directory using three different files
$ tar –tvf filename.tar # view/list the content of a tar file
$ tar –rvf existingfile.tar ~/newfile # to append/add a new file in
existing tar file/archive
$ tar –zcpvf myarchive.tar.gz ~/file1 ~/file2 # create and compress a
tar archive file OR
$ tar –zcpvf myarchive.tgz ~/file1 ~/file2
$ tar –zxpvf myarchive.tgz # extract a compressed tar archive file

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

 To run the penultimate command


$ !-2 #similarly other commands !-5, !-10, !-25 and so on

 Execute the last command that begins with a particular word


$ !man or $ !pwd

 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

 To save any of your text/statement in a file


$ echo hello my name is Raju >> myname.text

 To know the name of your host/network


$ hostname # know the hostname
$ hostname –i # know the network IP
$ ip addr show # show IP addresses and network interfaces
$ ifconfig # show IP addresses of all network interfaces
$ netstat –pnltu # show active ports
$ netstat –nutlp # show more information about a domain
 Adding and Deleting New Users in Linux PC
$ useradd Hari # add a new user and also set password
$ userdel Hari # delete an existing user after giving password
$ passwd # add a password to a user account
$ id # show details of the user
$ last # show the last logins
 Running multiple commands in one single command
$ Command1; Command2; Command3 # running multiple commands in
parallel
$ Command1 && Command2 && Command3 # if you only want the next
command to run when the first one is successful

To see the content of a file


$ more filename
 To take a snapshot of an active process
$ ps
 Editing a file
$ vim filename
$ nano filename
$ vi filename
2.2 Running multiple commands in one line
 Using semicolon operator (;): Applicable for independent commands
The most common practice is using a semicolon (;) between the chain of Linux commands. Using
the semicolon (;) operator, we can run multiple in a sequence irrespective of whether the previous
command was executed successfully or failed. The basic syntax of using the semicolon (;)
operator is:
$ command 1; command 2; command 3
 Using && (AND) operator: For sequential execution
If we want to run the chain of commands one by one in Linux that is related to the previous
command, we can use the AND (&&) operator in this case. The AND operator only allows the
user to run the next command when the previous command is executed successfully. So, we can
use the logical AND (&&) operator between the commands in the following way:
$ command 1 && command 2 && command 3
Example: $ mkdir my_project cd my_project
Output: username:~/my_project$
 Using the || (OR) operator: For concatenating the commands
The OR (||) the operator allows users to run the next command if the previous command fails and
gives an error. But, if the previous command is executed successfully then, the next command
will not run. Therefore, the OR (||) operator is used to concatenate multiple commands.
$ command 1 || command 2 || command 3

Example: $ mkdir personal || cd personal || pwd


mkdir: cannot create directory ‘personal’: file exists
Output: username:~/personal$
Note: We can also combine Linux commands by combining more than one operator such as AND
(&&) and OR (||) operators.
2.3 Getting information about a command
 Use the man command specifying the name of the command as an argument.
$ man pwd

A detailed description of the pwd command will be displayed.


 Many commands will also provide additional information when run with the --help command-line
option:
$ wc --help

2.4 Short cut keys


 Clear # clean the terminal
 Tab # autofill what you are typing
 Up Arrow # see the previous command
 Down Arrow # see the next command
 Delete # Delete character currently beneath the cursor
 Backspace # Delete character to the left of the cursor
 Ctrl+b OR left arrow # move cursor back one position
 Ctrl + f OR right arrow # move cursor forward one position
 Ctrl+C # stop and terminate the command (cuurent)
 Ctrl+Z # simply pause the command (currently working)
 Ctrl+S # accidental freezing your terminal
 Ctrl+Q # unfreezing (undo) your freezed terminal
 Ctrl+A # moves the cursor to the beginning of the line
 Ctrl+E # moves the cursor to the end of the line
 Ctrl+R # recall the last command that matches with provided
characters
 Ctrl+G # exit command history without running a command
 Env # show currently defined shell variable
 Exit # log out the current session

2.5 General installation and update commands


$ pip install <package name>
$ conda install <package name>
$ sudo apt install <package name>
$ sudo apt-get install <package name>
GeoAI for Urban Sensing, Summer School in Gammarth-Tunis, Tunisia
Technical Session (T2) on SAR and InSAR for Urban Cities

$ sudo apt-get upgrade


$ sudo apt-get update
$ sudo apt install default-jre #java install
$ sudo dpkg --install

2.6 Web download and installation commands


$ wget <download link> # To download some files from internet
$ sudo chmod +x <installer file.ext> #Make it executable
$ sudo ./<installer_file.sh> # for installation

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy