Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views6 pages

Linux CMD

The document provides an overview of various Linux commands categorized into file handling, text processing, system administration, process management, archival, networking, and file system management. It includes command syntax, usage examples, and explanations of file permissions and environment variables. Additionally, it covers the use of aliases and common vi editor commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Linux CMD

The document provides an overview of various Linux commands categorized into file handling, text processing, system administration, process management, archival, networking, and file system management. It includes command syntax, usage examples, and explanations of file permissions and environment variables. Additionally, it covers the use of aliases and common vi editor commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

8/22/2024

LINUX COMMANDS
Commands tell the operating system to perform set of operations.
The general syntax of the Linux commands is:
Appendix: Commonly Command [-options] <argument1, argument2, …, argument >
used shell CommAnds We can divide Linux commands into following categories
CAtegories
 File Handling  Archival
 Text Processing  Network
 System Administration  File Systems
 Process Management  Text Editor Commands

8/22/2024 68 8/22/2024 69

68 69

LINUX COMMANDS FILE HANDLING (1/4)


ls:
list directory contents
 Primary – man(manual) pages. Usage: ls [OPTION]... [FILE]…
 man <command> eg. ls, ls -l, ls LHC_School
 shows all information w.r.t. online manual
pwd:
pages related to the command
prints the name of current working directories
 Info <command> Usage: pwd
 Reads info documents about the command eg. mkdir LHC_School
 <command> --help
 shows the available options for that command cd:
changes directories
70 71
Usage: cd [DIRECTORY]
 Secondary – Books and Internet eg. cd LHC_School
8/22/2024
8/22/2024

70 71
8/22/2024

FILE HANDLING (2/4) FILE HANDLING (3/4)


mkdir: mv:
make directories move (rename) files
Usage: mkdir [OPTION] DIRECTORY... Usage: mv [OPTION]... SOURCE / DEST
eg. mkdir LHC_School eg. mv source.txt target_dir mv old.txt
new.txt
vim: rm:
Vi Improved, a programmers text editor Usage: vim remove files or directories Usage: rm
[OPTION] [file]... [OPTION]… [file]...
eg. vim file1.txt eg. rm file1.txt ,
cp: rm -rf some_dir
copy files and directories
Usage: cp [OPTION]... SOURCE / DEST 8/22/2024 73
eg. cp sample.txt sample_copy.txt cp sample_copy.txt
target_dir 72
8/22/2024

72 73

FILE HANDLING (4/4) PATTERN


find: A Pattern is an expression that describes a set of strings
search for files in a directory hierarchy which is used to give a concise description of a set,
Usage: find [OPTION] [path] [pattern] without having to list all elements.
eg. find file1.txt
find -name file1.txt Example:
ab*cd matches anything that starts with ab and ends
with cd etc.
history:
prints recently used commands Usage: ls *.txt – prints all text files
history
8/22/2024 74 rm *.obj – removes all object files

8/22/2024 75

74 75
8/22/2024

TEXT PROCESSING (1/3) TEXT PROCESSING (2/3)


cat: grep:
concatenate files and print on the standard print lines matching a pattern
output… Usage: grep [OPTION] PATTERN [FILE]...
Usage: cat [OPTION] [FILE]… eg. cat eg. grep -i apple sample.txt
file1.txt file2.txt wc:
cat -n file1.txt print the number of newlines, words, and bytes in
echo: files…
display a line of text Usage: wc [OPTION]... [FILE]...
Usage: echo [OPTION] [string] ... eg. echo I love eg. wc file1.txt wc -L file1.txt
Pakistan
echo $HOME
8/22/2024 76 8/22/2024 77

76 77

TEXT PROCESSING (3/3) LINUX FILE PERMISSIONS


 3 types of file permissions – read, write, execute
sort:  10-bit format from 'ls -l' command
sort lines of text files
Usage: sort [OPTION]... [FILE]...
eg. sort file1.txt sort -r file1.txt 1 234 567 8 9 10
file type owner group others

E.g. drwxrw-r-- : means d is directory, owner has all three permissions,


group has read and write, others have only read permission
 read permission = 4
 write permission = 2
8/22/2024 78  execute permission = 1 79

 E.g. rwxrw-r-- = 764



8/22/2024 E.g. 673 = rw-rwx-wx
78 79
8/22/2024

SYSTEM ADMINISTRATION (1/2) SYSTEM ADMINISTRATION (2/2)


chmod: passwd:
change file access permissions update a user’s authentication
Usage: chmod [OPTION] [MODE] [FILE] tokens(s) Usage: passwd [OPTION]
eg. chmod 744 calculate.sh eg. passwd
chown: who:
change file owner and group show who is logged on Usage: who [OPTION]
Usage: chown [OPTION]... OWNER[:[GROUP]] FILE... eg. who , who -b , who -q
eg. chown remo myfile.txt
su:
change user ID or become super-user Usage: su
[OPTION] [LOGIN]
eg. su remo, su 8/22/2024 81

8/22/2024 80

80 81

PROCESS MANAGEMENT ARCHIVAL


ps: tar:
report a snapshot of the current processes Usage: to archive a file
ps [OPTION] Usage: tar [OPTION] DEST SOURCE
eg. ps,ps -el tar -cvf /home/archive.tar /home/original tar -xvf
kill: /home/archive.tar
to kill a process(using signal mechanism) zip:
Usage: kill [OPTION] pid eg. kill -9 2275 package and compress (archive) files Usage: zip [OPTION]
DEST SOURSE
eg. zip original.zip original
unzip:
list, test and extract compressed files in a ZIP archive
8/22/2024 82 Usage: unzip filename
eg. unzip original.zip
8/22/2024 83

82 83
8/22/2024

NETWORK FILE SYSTEM (1/2)


SSH: fdisk:
SSH client (remote login program) partition manipulator eg. sudo fdisk -l
“ssh is a program for logging into a remote mach ine mount:
and forexecuting commands on a remote machine” mount a file system
Usage: ssh [options] [user]@hostname eg. ssh -Y Usage: mount -t type device dir
[email protected] eg. mount /dev/sda5 /media/target
scp: umount:
secure copy (remote file copy program) unmount file systems
“scp copies files between hosts on a network” Usage: umount [OPTIONS] dir | device... eg.
Usage: scp [options] [[user]@host1:file1] [[user]@host2:file2] umount /media/target
eg. scp file1.txt [email protected]:~/Desktop/
8/22/2024 85
8/22/2024 84

84 85

FILE SYSTEM (2/2) EDITOR COMMANDS


du: vi:
estimate file space usage Usage: du Vi Improved, a programmers text editor Usage:
[OPTION]... [FILE]... vim [OPTION] [file]...
eg. du e.g. vi hello.c
df: gedit:
report file system disk space usage A text Editor. Used to create and edit files. Usage:
Usage: df [OPTION]... [FILE]... gedit [OPTION] [FILE]...
eg. df eg. gedit
quota: pico:
display disk usage and limits Usage: Simple and very easy to use text editor
quota [OPTION] Usage: pico [OPTION] eg. pico
eg. quota -v
8/22/2024 86 8/22/2024 87

86 87
8/22/2024

USING ALIASES ENVIRONMENT VARIABLES (1/2)


Aliases provide command-substitution functionality. They can be used to create Environment variables refers to global settings that control the function of the
new commands or modify the default behaviour of existing commands shell and other Linux programs. They are sometimes called global shell
variables
Syntax: alias <string entered by user>=<string substituted by the shell> or in simple words
They define the user environment and are read from initialization files each
The alias command is used to view and create aliases time a user logs in…

called with no arguments, it prints out the current aliases To view the value of a variable, type:
alias name=value creates a new alias printenv VARNAME OR echo $VARNAME
custom user aliases are stored in .bashrc or .cshrc
To check your environment, type
printenv OR env
Examples:
To Set Environment Variable
alias rm = 'rm -i' (change the behaviour of rm to confirm deletes) setenv EDITOR “vim”
alias ll = 'ls -l | more' (create a new command for friendly file listings)
Some common environment variables:
8/22/2024 88 HOME: Your home directory (often be abbreviated as “~”)
PWD: Current working directory
EDITOR: User’s preferred text editor
8/22/2024 89

88 89

USEFUL vi EDITOR COMMANDS


ENVIRONMENT VARIABLES (2/2)
Some common environment variables:

EDITOR: Sets the editor to be used by programs such as mail clients


Arrow keys Move cursor ^G show current file and line
PATH: Specifies directories to be searched for executables.
hjkl Same as arrow keys ^F forward screen backward
SHELL: The default login shell
insert / i x Insert text ^B screen
USER: Current loggedin user’s name
dw dd delete a character ^D scroll down half screen
TERM: The type of terminal you are running (e.g. vt100,xterm, & ANSI) delete a word delete ^U scroll up half screen
LD_LIBRARY_PATH: It is a colon seperated set of directories where libraries a line nG go to the beginning of the
should be searched for 3dd deletes 3 lines specified line (end default),
u undo previous change where n is a line number
ZZ exit vi , saving changes /pat search pat (next line matching
To reload any initialization file without having to logout and login again, type ESC end insert or incomplete pat)
source <filename> command (delete or ^E scroll window down one line
e.g. source ~/.bashrc source ~/.tcshrc DEL rubout) interrupts ^Y scroll window up one line top
erase last character H line on screen
(backspace) last line on screen
Profile files: session startup files are hidden files, find them via command “ls –a”…. ^H L
erase last word middle line on screen
.tcshrc .cshrc .bashrc etc… ^W M

8/22/2024 90 8/22/2024 91

90 91

You might also like