You are on page 1of 2

Linux Commands

Directory Operations File Searching Processes Editing Text Files


pwd Show current directory grep pattern file Search for lines with ps Show processes of user nano Text editor
cd dir
pattern in file ps -e
Change to directory dir Show all processes Shortcuts
grep -v Inverted search
mkdir dir Create a new directory dir ps -fA Show all processes in detail Ctrl-o Save file
grep -r Recursive search
rmdir dir Delete directory dir top Show processes in real-time Ctrl-x Close file
grep -e patt -e patt Multiple patterns
ls dir List contents directory dir cmd & Run command in background Ctrl-r Open file
locate file Quick search for file Ctrl-c Stop (kill) currently active process Ctrl-k Cut line of text
Special Directories ls Options which cmd Find location of binary Ctrl-z Suspend currently active process Ctrl-u Paste line of text
Current directory -a all inc. hidden find dir -name Find file with pattern
pattern bg Place suspended process in Ctrl-d Delete character
.. Up a directory -l long format in dir
background Ctrl-w
. -t
Search for text
Current directory sort by time fg Bring background process to
Standard IO Streams
~ Home directory -S sort by size foreground Text File Operations
stdin Input typed on the command line
/ Root directory -r reverse order kill pid Kill process with process id pid wc Line, word and
stdout Output on the screen
- -R kill -9 pid Kill process pid (ungraceful) character count
Previous directory recursive
stderr Errors output on the screen sort file Sort file, line by line
echo string Write string to stdout
File Operations Bash Shortcuts uniq file Display only unique
touch file Create file file Ctrl-k Cut line of text lines of file
Redirection
cp file1 file2 Copy file1 to file2 Ctrl-y Paste line of text sed 's/abc/def/g' file Replace all occurrences
cmd > file Output of cmd to file
Ctrl-e
of abc with def, output
mv file1 file2 Move file1 to file2 Go to end of line
cmd < file file used as input to cmd to stdout
rm file Delete file Ctrl-a Go to start of line
cmd >> file Append output to file cut -d “ “ -f N file Display field N of
cat file Display contents of file TAB Autocomplete command/file space delimited file
cmd 2> file Write errors to file
cat file1 file2 TAB-TAB Show list of possible cut -d “,” -f M-N file Display fields M-N of
Concatenate files cmd &> file Errors and stdout to file autocompletes comma delimited file
less file Display file (paginated), q to
quit up arrow Scroll previous commands
Pipes and Multiple Commands GUI applications via Command line
head file Show first 10 lines cmd1 | cmd2 Stdout of cmd1 is used as input to down arrow Scroll previous commands gedit Text editor
tail file cmd2 history List recent commands
Show last 10 lines wireshark Packet capture and display
-n N N lines cmd1 |&cmd2 Stderr of cmd1 is used as input to !! Repeat last command eog
-f Continuos update cmd2 Image viewer
!N Execute command N from history
cmdpart1 \ Continue command on next line evince PDF viewer
Help cmdpart2 !abc:p Print last command starting with nautilus File explorer
man cmd Manual page for cmd cmd1; cmd2 Execute cmd1 then cmd2 abc
man -k word Search for manual page with word !abc Execute last command starting Administrator Privileges
with abc
-h Commands show help when used sudo cmd Execute cmd with admin privilege
su username Switch to user username
r733
Networking Commands and Files
Interface Configuration Statistics Ping
ifconfig [<interface>] [up | down] netstat [-t | -i | -s | -r] [-n] ping [-c <count>] [-s <packetsize>] [-i <interval>] <destination>
ifconfig <interface> <ipaddress> netmask
<netmask> Tracepath Routing
ethtool <interface> tracepath <destination> route [-n]
ethtool -k <interface> route add -net <netaddress> netmask <subnet> [gw <gateway>] [dev <interface>]
File: /etc/network/interfaces route del -net <netaddress> netmask <subnet> [gw <gateway>] [dev <interface>]
DNS
nslookup <domain> [<dnsserver>] route add default gw <gateway>
Remote Login File: /etc/resolv.conf sysctl net.ipv4.ip_forward=[0 | 1]
ssh [-l <username] <address> File: /etc/hosts File: /proc/sys/net/ipv4/ip_forward

File Transfer ARP Firewall


nc -l <port> arp [-n] iptables -A <chain> [<options>]
nc <ip> <port> where <options> include:
scp <srcfile> <address>:<dstdir> [-s <sourceip>] [-d <destip>] [-i <ininterface>] [-o <outinterface>]
scp <address>:<srcfile> <dstdir>
DHCP [-p <protocol>] [--sport <sourceport>] [--dport <destport>]
dhclient [<interface>]
wget <url> [-j <action>]
File: /var/lib/dhcp/dhclient.leases
iperf -s iptables -D <chain> [<options>]
iperf -c <address> iptables -L <chain>
Web Server iptables -F <chain>
apache2ctl [start | stop | restart] where <chain> may be: INPUT | OUTPUT | FORWARD
Packet Capture htpasswd <passwordfile> <username>
tcpdump [-i <interface>] [-w <file>] Dir: /etc/apache2/sites-available/
Dir: /var/www/

File Permissions Security


Access Rights Output of ls -l Random Numbers
r read file; list the contents of directory E.g.: -rw-rwx--- drwxr-x--x echo $RANDOM Generate random integer [0..32767]
First letter indicates file type:
w write to file; create and remove files in direct. cat /dev/urandom | xxd -l 1 -b Generate 8 bit random value, binary
d = directory
x execute file; access files in directory - = normal file openssl rand 16 -hex Generate 16 Byte random value, hex
Next 9 letters: access right
letter indicates the permission
Subjects OpenSSL (following must be preceded with openssl)
is set; - indicates the
u user that owns the file enc -des-ecb -in p.txt -out c.bin Symmetric encrypt p.txt using DES-ECB
permission is not set
g users in the file’s group enc -d -des-ecb -in c.bin -out r.txt Symmetric decrypt c.bin using DES-ECB
Modes
o other users dgst -md5 file MD5 hash of file
Modes can be specified by
a all users, i.e. the above three) combining subject with access genpkey -algorithm RSA -out priv.pem Generate RSA public/private key pair
right pkey -in priv.pem -out pub.pem -pubout
+ Grant with right
Extract public key from key pair, save in pub.pem
Commands
- Remove the right pkey -in priv.pem -text View public/private key values, text
ls -l display directory contents = Set the right
dgst -sha1 -sign priv.pem -out s.bin p.txt Sign p.txt using SHA and private key in priv.pem
stat file display file status and inode info Examples:
u+r pkeyutl -encrypt -in p.txt -pubin -inkey pub.pem -out c.bin Encrypt p.txt using pub.pem, output c.bin
df report file system disk usage g-rw
u+r,g-wx,o-r pkeyutl -decrypt -in c.bin -inkey priv.pem -out r.txt Decrypt c.bin using priv.pem, output r.txt
chmod mode file change file mode bits, i.e. set a=rx
permissions dgst -sha1 -verify pub.pem -signature s.bin r.txt Verify signature of r.txt

You might also like