0% found this document useful (0 votes)
13 views

Bash Commands

Uploaded by

igteszt9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Bash Commands

Uploaded by

igteszt9
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Bash Commands Command Lists

uname -a Show system and kernel cmd1 ; cmd2


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

Screen Shortcuts
screen
Start a screen session.
screen -r
Resume a screen session.
screen -list
Show your current screen sessions.
CTRL-A
Activate commands for screen.
CTRL-A c
Create a new instance of terminal.
CTRL-A n
Go to the next instance of terminal.
CTRL-A p
Go to the previous instance of terminal.
CTRL-A "
Show current instances of terminals.
CTRL-A A
Rename the current instance.
More screen info at:
http://www.gnu.org/software/screen/

You might also like