Blog Details

Home Blogs

blog-img01

Linux Commands

Linux Commands

Linux Commands
Command NameDescriptionExample
File/Directory
ls List files ls -l

ls -alrt *.html
ls -al formatted listing with hidden files ls -al file.htm
cp Copy files cp sourcefile destinationfile
cp -r Copy directory, create destination directory if it doesn’t exist cp -r sourcedir destinationdir

cp -r file* subdir/
mv Move/rename files mv sourcefile destination file

mv file* ubdir/
rm Remove/delete files rm filename
rm -r Remove/delete directory rm -r directory
rm -f Force to remove file rm -f *.aux
rm -rf Force to remove directory rm -rf subdir/
ln Link files ln
ln -s Create symbolic link to file ln -s file link
cd Change Directory to home cd
cd dir Change directory to directory cd ~/2350/hw cd bin
pwd show Present Working Directory pwd
mkdir Make new Directory mkdir 2005fall
rmdir Remove/delete Directory rmdir 1995fall
touch create or update file touch file.txt
File Viewing
cat Display text contents cat file1.txt file2.txt file3.txt
less page through files less
head output first few lines of file head -5 file.txt
tail output last few lines of file tail -5 file.txt
tail -f output the contents of files as it grows, starting with last 10 lines tail -f filename
nl Number Lines nl
od view binary data od
xxd view binary data xxd
gv view postscript/pdf files gv
xdvi view TeX DVI files xdvi
more output the contents of the file more filename
echo Print to screen echo “This is output”
strings Text embedded in binary strings a.out
File Creation and Edition
emacs Text editor emacs file.tex
vim Text editor vim file.tex
vi Text editor vi file.txt
nedit Text editor nedit file.txt
pico Text editor pico file.txt
latex Compiles DVI documents
pdflatex Compiles PDF documents
umask set default file protections umask
soffice edit word/excel/powerpoint docs soffice
abiword edit word documents abiword
gnumeric edit excel documents gnumeric
File Properties
stat Display file attribute stat
wc Word Count – count bytes/words/lines wc file.txt
file identify File Types file *
touch Change file timestamps touch
File Permission
chown Change file Owner chown
chgrp Change group ownership chgrp appm2350 index.htm
chmod OwnerGroupWorld Change file permissions (4-read, 2-write, 1-execute) chmod 754 file.htm (rwx for Owner, rx for Group and r for
chattr Change advanced file Attributes chattr
lsattr List advanced file Attributes lsattr
File Location
find locate files find
locate find all instances of filename locate filename
slocate locate files via index slocate
which show which application or file will be run by default which application/filename
whereis show possible locations of apps/files whereis application/filename
grep pattern search for ‘pattern’ in files grep pattern files
grep -r pattern search recursively for pattern in dir grep -r pattern dir
command | grep pattern search for pattern in the output of command
System Information
date show the current date and time date
cal show this month’s calendar cal 12 2005
uptime show current uptime
w display who is online w
uname -a show kernel information
cat /proc/cpuinfo show cpu information
cat /proc/meminfo show memory infomation
man show manual for command man ls man -k editor
free show memory and swap usage free
File/Text Manipulation
grep Find word/string grep keyword file1 file2 file3
cut extract columns cut
paste append columns paste
tr Translate characters tr
sort Sort lines sort -r -n file.txt
uniq locate identical lines uniq
tee copy stdin to a file and to stdout simultaneously tee
File Compression and Compilers
gzip compress GNU files & rename it gzip file.tar (new name file.gz)
gzip -d decompress file.gz back to file gzip -d file.gz
gunzip Uncompres files gunzip file.tar.gz
compress Compress Unix files compress
bzip2 compress BZip2 files bzip2
zip compress Windows files zip
tar cf Creates a tar named file.tar contains files tar cf file.tar file1 file2 file3 file4
tar xf Extract the files from file.tar tar xf file.tar
tar czf Create a tar with Gzip compression tar czf file.tar.gz files
tar xzf Extract a tar using Gzip tar xzf file.tar.gz
tar cjf Create a tar with Bzip2 compression tar cjffile.tar.bz2
tar xjf Extract a tar using Bzip2 tar xjffile.tar.bz2
cc c++ gcc g++ C and C++ compilers cc -o myprogramprogA.c
f77 f90 f95 Fortran compilers f90 -o myprogram progA.f90
File Comparision
diff compare files line by line diff file1.txt file2.txt
comm Compare sorted files comm
cmp Compare files byte by byte cmp
md5sum compute checksums md5sum
Disks and File Systems
df show Disk Free space df
mount make disk accessible mount
fsck Check a disk for errors fsck
sync flush disk caches sync
du measure Disk Usage du -k
Backup and Remote Storage
mt Control a tape drive mt
dump back up a disk dump
restore Restore a dump restore
tar read/write Tape Archives tar
cdrecord burn a CD cdrecord
rsync mirror a set of files rsync
Printing
lpr Print files lpr
lpq view Print Queue lpq
lprm Remove Print jobs lprm
Spelling Operations
look Look up spelling lookstri
aspell check Spelling interactively aspell
spell Find misspelled words spell file.txt
Process Management
ps list all Processes ps -ef
w list user’s processes w
uptime view the system load uptime
top display/monitor running processes top
xload monitor system Load xload
free display Free memory free
kill Terminate processes killpid (pid=process id/no.)
kill all Kill All process by same name kill all ProcessName
nice set process priorities nice ./a.out
renice Change process priorities renice
bg lists stopped or Background jobs
fg brings the most recent job to foregrond fg n (n=job name/no.)
jobs In current shell jobs
Job Scheduling
sleep wait for some time sleep
watch run programs at set intervals watch
at schedule a job at
crontab schedule repeated jobs crontab
adduser Adds a new user to the system adduser username
Hosts/Users
uname print system information uname
hostname print the system’s Hostname hostname
whoami Who you are logged in as whoami
finger Display information about user finger username
passwd Change password passwd
w who whoami User identities w who whoami
Networking
ifconfig set/display network information ifconfig
host look up DNS host
whois look up domain registrants whois domainname
dig get DNS information dig domainname
Reverse lookup host dig -x hostname
ping Check if host is reachable ping hostname
traceroute view network path to a host traceroute
ssh Securely log into remote hosts ssh
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
Connect to host on ‘port’ as user ssh -p port
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
Add your key to host for user to enable a keyed/passwordless login ssh -copy
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
ssh ssa.ccny.cuny.edu -l username
telnet log into remote hosts telnet
scp Securely Copy files between hosts scp myfile ssa.ccny.cuny.edu:subdir/file8
sftp Securely copy files between hosts sftp
ftp copy files between hosts ftp
evolution GUI email client evolution
mutt text based email client mutt
mail minimal email client mail
mozilla web browser mozilla
lynx text only web browser lynx
wget retrieve/download web pages/files wget filename
Continue a stopped download wget -c filename
slrn read Usenet news slrn
gaim instant messaging/IRC gaim
talk Linux/Unix chat talk
write send messages to terminal write
mesg prohibit talk/write mesg
pine Email pine
mailx Email mailx
[email protected]
This email address is being protected from spambots. You need JavaScript enabled to view it.
Audio/Video
grip play CDs and Rip MP3s grip
xmms play audio files xmms
cdparanoia rip audios cdparanoia
audacity edit audios audacity
xcdroast burn CDs xcdroast
Installation
./configure ./configure
make install Install from source
dpkg -i Install a package (Debian) dpkg -i pkg.deb
rpm -Uvh Install a package (RPM) rpm -Uvhpkg.rpm
Shortcuts
Ctrl+C halts the current command
Ctrl+Z stops the current command, resume with fgin the foreground or bg in the background.
Ctrl+D log out of current session, similar to exit
Ctrl+W erases one word in the current line
Ctrl+U erases the whole line
Ctrl+R brings up a recent command
exit log out of current session
!! repeats the last command
alias Allows you to substitute a new name for a command alias help=man, alias long=ls -al
alias dir ‘/bin/ls -al \!* | more;’
& Run in background nice ./a.out&
> Redirect to file nice ./a.out>results.out&
>> Append to file nice ./a.out>>more.out&
< Input from file nice ./a.out< input.dat >results.out&
| Pipe to another program cat *.dat| more
; Separates commands ./a.out< input1.dat ; /a.out< input2.dat ; ls
$ Define variable set echco $variablename
* ? Wildcard characters ls *.tex ; lsa* ; ls *.???; lsfile?.txt
!! $! Last command, last word echo “!!”
~/.cshrc Initialization file Define shell variables and aliases
~/.login Initialization file Set 1-time login information
~/.ssh/known_hosts ssh keys file Keys accepted from other hosts; sometimes needs editing.
© 2012 Md. Khurshed Alam Nayeem

Leave a Reply

Your email address will not be published. Required fields are marked *