Linux Command Line Cheat Sheet: by Via
Linux Command Line Cheat Sheet: by Via
uname -a Show system and export NAME=value Set $NAME to value cmd1 ; cmd2
kernel $PATH Executable search Run cmd1 then cmd2
head -n1 /etc/issue Show distribution path
cmd1 && cmd2
mount Show mounted filesy‐ $HOME Home directory
Run cmd2 if cmd1 is successful
stems $SHELL Current shell
cmd1 || cmd2
date Show system date
Run cmd2 if cmd1 is not successful
uptime Show uptime IO Redirection
cmd &
whoami Show your username cmd < file
Run cmd in a subshell
man command Show manual for Input of cmd from file
command cmd1 <(cmd2)
Directory Operations
Output of cmd2 as file input to cmd1
Bash Shortcuts pwd Show current directory
cmd > file
CTRL-c Stop current command mkdir dir Make directory dir
Standard output (stdout) of cmd to file
CTRL-z Sleep program cd dir Change directory to dir
cmd > /dev/null
CTRL-a Go to start of line cd .. Go up a directory
Discard stdout of cmd
CTRL-e Go to end of line ls List files
cmd >> file
CTRL-u Cut from start of line
Append stdout to file ls Options
CTRL-k Cut to end of line
cmd 2> file -a Show all (including hidden)
CTRL-r Search history
Error output (stderr) of cmd to file -R Recursive list
!! Repeat last command
-r Reverse order
!abc Run last command starting with cmd 1>&2
abc -t Sort by last modified
stdout to same place as stderr
!abc:p Print last command starting -S Sort by file size
cmd 2>&1
with abc -l Long listing format
stderr to same place as stdout
!$ Last argument of previous -1 One file per line
cmd &> file
command -m Comma-separated output
Every output of cmd to file
ALT-. Last argument of previous -Q Quoted output
command cmd refers to a command.
find /dir/ -user name Find files owned by ps Show snapshot of processes screen -list
name in dir top Show real time processes Show your current screen sessions.
find /dir/ -mmin num Find files modifed kill pid Kill process with id pid CTRL-A
less than num
pkill name Kill process with name name Activate commands for screen.
minutes ago in dir
killall name Kill all processes with names CTRL-A c
whereis command Find binary / source /
beginning name
manual for command Create a new instance of terminal.
Concatenate files and output CTRL-K Cut marked text or line Rename the current instance.
CTRL-U Paste text More screen info at:
less file1
Navigate File http://www.gnu.org/software/screen/
View and paginate file1
ALT-/ End of file
file file1
File Permissions
CTRL-A Beginning of line
Get type of file1
chmod 775 file
CTRL-E End of line
cp file1 file2
Change mode of file to 775
CTRL-C Show line number
Copy file1 to file2
CTRL-_ Go to line number chmod -R 600 folder
mv file1 file2
Search File Recursively chmod folder to 600
Move file1 to file2
CTRL-W Find chown user:group file
rm file1
ALT-W Find next Change file owner to user and group to
Delete file1 group
CTRL-\ Search and replace
head file1
More nano info at:
File Permission Numbers
Show first 10 lines of file1 http://www.nano-editor.org/docs.php
First digit is owner permission, second is
tail file1
Screen Shortcuts group and third is everyone.
Show last 10 lines of file1
Calculate permission digits by adding
screen
tail -F file1
numbers below.
Start a screen session.
Output last lines of file1 as it changes
4 read (r)
screen -r
2 write (w)
Watch a Command Resume a screen session.
1 execute (x)
watch -n 5 'ntpq -p'
Issue the 'ntpq -p' command every 5
seconds and display output