Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
852 views

Linux Cheat Sheet

The document summarizes various file commands, network commands, process management commands, system information commands, user administration commands, and mounting commands for Linux/Unix systems. It provides examples of how to use commands like ls, cd, ping, ifconfig, ps, uptime, whoami, mount, and umount.

Uploaded by

Ökkeş Aktaş
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
852 views

Linux Cheat Sheet

The document summarizes various file commands, network commands, process management commands, system information commands, user administration commands, and mounting commands for Linux/Unix systems. It provides examples of how to use commands like ls, cd, ping, ifconfig, ps, uptime, whoami, mount, and umount.

Uploaded by

Ökkeş Aktaş
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

File Commands Network

ls – directory listing ping host – check if host is reachable


ls -al – formatted listing with hidden files Example: ping www.ceng.metu.edu.tr
cd dir - change directory to dir traceroute host – display the route to host
cd – change to home netstat – print network connections, routing tables and
pwd – show current directory interface statistics
mkdir dir – create a directory dir whois domain – get whois information for domain
rm file – delete file dig domain – get DNS information for domain, similar to
rm -r dir – delete directory dir host domain
rm -f file – force remove file dig -x host – reverse lookup host
rm -rf dir – force remove directory dir * hostname – print the system’s hostname
cp file1 file2 – copy file1 to file2 wget file – download file
cp -r dir1 dir2 – copy dir1 to dir2; create dir2 if not exists wget -c file – continue a stopped download
mv file1 file2 – rename or move file1 to file2 ifconfig – list IP addresses for all devices on the machine
if file2 is an existing directory, moves file1 into file2 ifup eth0 – bring up network interface eth0
ln -s file link – create symbolic link link to file ifdown eth0 – bring down network interface eth0
stat file – display file attributes iptables – administration tool for packet filtering and NAT
touch file – create or update file ipchains – IP firewall administration
cat > file – places standard input into file route – show / manipulate the IP routing table
more file – output the contents of file lynx – text based web browser
head file – output the first 10 lines of file pine – e-mail and news reader
tail file – output the last 10 lines of file tin – text based news reader
tail -f file – output the contents of file as it grows, starting
with the last 10 lines
SSH
chmod octal file – change the permissions of file
ssh user@host – connect to host as user
to octal, which can be found separately for user,
ssh -p port user@host – connect to host on port port as
group, and world by adding:
user
● 4 – read (r) ssh-copy-id user@host – add your key to host for user to
● 2 – write (w) enable a keyed or passwordless login
● 1 – execute (x) ssh -L localport:remotehost:remoteport user@host –
E.g.: create a tunnel to connect to remotehost’s remoteport
chmod 777 – read, write, execute for all from localport
chmod 755 – rwx for owner, rx for group and world E.g.: ssh -L 8080:www.ceng.metu.edu.tr:80
For more options, see man chmod e1XXXXXX@login.ceng.metu.edu.tr
chown accountname file – change the owner of the file point web browser to http://localhost:8080/ to connect to
called file to accountname user www.ceng.metu.edu.tr
sftp – used for interactive file transmission
Process Management put file – transfer file from local computer to the remote
ps – display your currently active processes computer
pstree – display your currently active processes in get file – transfer file from the remote computer to local
hierarchical order from parent child computer
top – display all running processes
kill pid – kill process id pid Searching
killall proc – kill all processes named proc * grep pattern files – search for pattern in files
bg – lists stopped or background jobs; resume a stopped grep -r pattern dir – search recursively for pattern in dir
job in the background command | grep pattern – search for pattern in the output
fg – brings the most recent job to foreground of command
fg n – brings job n to the foreground updatedb – create or update the database of files on all
fuser file – show processes using file file systems attached to the linux root directory
locate file – find all instances of file using database index.
This assumes updatedb has already been used E.g.: apt-get install gcc – install gnu c compiler
find dir -name fname – starting with the directory called aptitude search pattern– search for packages matching
dir, look for the file called fname pattern
Example: synaptic –graphical management of software packages
find / -name ceng111.pdf – starting with the root
directory, look for the file called ceng111.pdf
Starting & Stopping
shutdown -h now – shutdown the system now and do not
System Info reboot
date – show the current date and time halt – stop all processes - same as above
cal – show this month's calendar shutdown -r 5 – shutdown the system in 5 minutes and
uptime – show the system load reboot
which commandname – show which program is executed shutdown -r now – shutdown the system now and reboot
by a given commandname reboot – stop all processes and then reboot – same as
w – display who is online above
whoami – who you are logged in as startx – start the X system
who – list the login name, terminal name and login time
for each logged in user
finger – display the list of the users on the system
User Administration
adduser accountname – create a new user called
finger user – display information about user on the system
accountname
uname -a – show kernel information
passwd accountname – give accountname a new
cat /proc/cpuinfo – cpu information
password
cat /proc/meminfo – memory information
login accountname – login user called accountname after
lshw – list all hardware components
a signoff or to change the current user
lsof – display list of open files
su – log in as superuser from current login
man command – show the manual for command
sudo – allow a permitted user to execute a command as the
man -k subject – list manual pages for subject similar to
superuser or another user
apropos subject
exit – log out of current session. use after su to relinquish
df – show disk usage
superuser rights
du – show directory space usage
quota – manage disk quota
free – show memory and swap usage Mounting
whereis app – show possible locations of app mount -t iso9660 /dev/cdrom /mnt/cdrom – mount the
which app – show which app will be run by default device cdrom and call it cdrom under the /mnt directory
env – display, set or remove environment variables mount -t vfat /dev/hda1 /mnt/cdrive – mount hard disk
set – manipulate shell variables and functions “a” as a VFAT file system and call it cdrive under the /mnt
mount -t ntfs /dev/hda1 /mnt/windows – mount hard disk
Compression “a” as a NTFS file system and call it windows under /mnt
tar -cf file.tar files – create a tar named file.tar containing umount /mnt/cdrom – unmount the cdrom
files
tar -xf file.tar – extract the files from file.tar
tar -czf file.tar.gz files – create a tar with Gzip Miscellaneous
compression wc -[b/w/l] – count [c]bytes / [w]ords / [l]ines
tar -xzf file.tar.gz – extract a tar using Gzip sort file – sort file
tar -cjf file.tar.bz2 – create a tar with Bzip2 compression cmp file1 file2 – compare files byte to byte
tar -xjf file.tar.bz2 – extract a tar using Bzip2 comm file1 file2 – compare sorted files
gzip file – compress file and renames it to file.gz diff file1 file2 – compare files line by line
gzip -d file.gz – decompress file.gz back to file md5sum file – compute md5 checksum of file
bzip2 -k file – compress file as file.bz2 and keep the unix2dos – convert text files from/to linux format
original file echo – display output
bunzip2 file.bz2 – decompress file.bz2 back to file E.g.: echo $HOME – displays user’s home directory path
history – display the list of commands executed previously
clear – clear the terminal screen
Installation sleep time – delay for a specified amount of time in
install from source: seconds
./configure command & – execute command in background
make
Example: sleep 2 &
make install
command --help – used as a switch to any command to
dpkg -i pkg.deb – install a package (Debian)
display its help page
see also apt-get
E.g.: ls –help
rpm -Uvh pkg.rpm – install a package (RPM)
fdisk – modify the partition table
apt-get install pkg – install a package (Debian)
grub – GRand Unified Bootloader, boot loader program
this is a higher level tool compared to dpkg
Shortcuts Configuration Files
Ctrl+C – halt the current command $HOME/.bash_profile – bash system wide and per user
Ctrl+Z – stop the current command, resume with fg in the init files
foreground or bg in the background $HOME/.bashrc –user init files
Ctrl+D – log out of current session, similar to exit /etc/bash.bashrc – shell variables
Ctrl+W – erase one word in the current line /etc/bash.bashrc.local – overrides /etc/bash.bashrc
Ctrl+U – erase the whole line /etc/bashrc – bash system wide and per user init files
Ctrl+R – bring up a recent command /etc/default – default for certain commands
!! - repeats the last command /etc/cron.* – there are 4 directories that automatically
Tab – auto complete the command if there is only one execute all scripts within the directory at intervals of hour,
option, or else show all the available options day, week or month
Shift+PgUp – scroll the command history (press Enter to /etc/exports – NFS server export list
execute a historical command) /etc/fstab – list of devices and their associated mount
Shift+PgDown – scroll the command history back points. edit this file to add cdroms, DOS partitions and
Alt+Tab – walk through windows (Alt+Shift+Tab to floppy drives at startup
walk backwards) /etc/group – group listing, passwords and member lists
Ctrl+Tab – walk through desktops (Ctrl+Shift+Tab to /etc/host.allow – TCP wrapper host control files
walk backwards) /etc/host.config – host name information look up order
Ctrl+Alt+Backspace – stop X server (some systems use /etc/host.deny – TCP wrapper host control files
Ctrl+Alt+Esc) /etc/HOSTNAME – contains full hostname including
Ctrl+Alt+F1 – switch to text mode console 1 domain
Ctrl+Alt+Fn – switch to text mode console n (n=1..6) /etc/hosts – a list of all know host names and IP addresses
Ctrl+Alt+F7 – switch back to graphic terminal 1 on the machine
Ctrl+Alt+Fn – switch back to graphic terminal n (n=7..12) /etc/init.d/ – directory containing run level scripts for
MiddleMouseButton – paste the highlighted text system startup
/etc/inittab – control file that determines how the system
boots
/etc/motd – message of the day broadcast to all users at
login
/etc/networks – file that contains network ranges and their
Important Directories associated names
. – refers to current directory /etc/nsswitch.conf – configuration file that defines the
.. – refers to parent directory order in which look up hostnames/dns names occurs
~ – refers to current user’s home directory /etc/passwd – file that has information that defines user
/ – the root of the file system, all other files and directories accounts on the server their shell, UID, default group,
use this as a starting point home directory and either a hash for their password or a
/bin/ – binaries directory - contains common executables marker indicating that it is in the shadow password file
for system operation /etc/profile – system wide environment variables for all
/boot/ – directory containing persistent boot information users
and executables, such as kernel, and initrd, grub.conf /etc/profile.local – change to your global variables should
/dev/ – devices directory be made here
/dev/fd0 – block device that refers to the first floppy drive /etc/protocols – this file contains protocol IDs and their
/dev/sda – block device that refers to the first hard drive names. useful for determining network traffic problems
/dev/lp0 – block device that refers to the first parallel port /etc/rc.d/rc.inet1 – IP address, network mask, default
(LPT1 in Windows) gateway are in these files
/etc/ – configuration files directory /etc/rc.d/rc.local – bash script that is executed at the end
/home/ – the mount point or directory where user’s of login process. similar to autoexec.bat in DOS
personal data is stored /etc/resolv.conf – defines IP addresses of DNS servers
/lib/ – library files directory /etc/services –TCP/IP services and ports mapping
/mnt/ – mount point directory /etc/shadow – read-only to root access processes, used to
/media/ – mount point directory avoid theft of user password
/proc/ – kernel process information directory /etc/shells – serves as the list of valid shells that may be
/root/ – root user’s home directory loaded
/sbin/ – system binaries directory /etc/smb.conf – config file for the SAMBA server. allows
/tmp/ – temporary directory file and print sharing with Microsoft clients
/usr/ – this directory is used as a system resource. many /etc/sysconfig/ – a directory containing system
times, libraries, applications, and source code are installed configuration files
in this folder. kernel compiling usually takes place in the /etc/sysconfig/network – the networking configuration
/usr/src/linux/ subdirectory file, specifies network interfaces, IP addresses and other
/var/ – log files are generally stored in this directory or log protocols
subdirectory /etc/X11/xorg.conf – configuration file for X Server
VI REFERENCE
VI REFERENCE
EDITING
MOVEMENT
Entering Text
By Character a append after cursor
A or $a append at end of line
i insert before cursor
I or _i insert at beginning of line
o open line below cursor
O open line above cursor
cm change text (m is movement)

By Line Cut, Copy, Paste (Working w/Buffers)


nG to line n dm delete (m is movement)
0, $ first, last position on line dd delete line
^ or _ first non-whitespace char on line D or d$ delete to end of line
+, - first character on next, previous line x delete char under cursor
X delete char before cursor
By Screen ym yank to buffer (m is movement)
^F, ^B scroll forward, back one full screen yy or Y yank to buffer current line
^D, ^U scroll forward, back half a screen p paste from buffer after cursor
^E, ^Y show one more line at bottom, top P paste from buffer before cursor
L go to the bottom of the screen “bdd cut line into named buffer b (a..z)
z↵ position line with cursor at top “bp paste from named buffer b
z. position line with cursor at middle
z- position line with cursor at
Searching and Replacing
Marking Position on Screen /w search forward for w
mp mark current position as p (a..z) ?w search backward for w
`p move to mark position p /w/+n search forward for w and move down n
'p move to first non-whitespace on line lines
w/mark p n repeat search (forward)
N repeat search (backward)
:s/old/new replace next occurence of old with new
Miscellaneous Movement :s/old/new/g replace all occurences on the line
fm forward to character m :x,ys/old/new/g replace all ocurrences from line x to y
Fm backward to character m :%s/old/new/g replace all occurrences in file
tm forward to character before m :%s/old/new/gc same as above, with confirmation
Tm backward to character after m
w move to next word (stops at punctuation)
W move to next word (skips punctuation)
Miscellaneous
b move to previous word (stops at
n>m indent n lines (m is movement)
punctuation)
n<m un-indent left n lines (m is movement)
B move to previous word (skips punctuation)
. repeat last command
e end of word (punctuation not part of word)
U undo changes on current line
E end of word (punctuation part of word)
u undo last command
), ( next, previous sentence
J join end of line with next line (at <cr>)
]], [[ next, previous section
:rf insert text from external file f
}, { next, previous paragraph
^G show status
% goto matching parenthesis () {} []

You might also like