Linux Commands


Linux Commands 1

posted Oct 13, 2009, 12:54 AM by JR A

Bash Commands

Show system and kernel
Show distri­bution
Show mounted filesy­stems
Show system date
Show uptime
Show your username
Show manual forcommand

Bash Shortcuts

CTRL-c
Stop current command
CTRL-z
Sleep program
CTRL-a
Go to start of line
CTRL-e
Go to end of line
CTRL-u
Cut from start of line
CTRL-k
Cut to end of line
CTRL-r
Search history
!!
Repeat last command
!abc
Run last command starting withabc
!abc:p
Print last command starting withabc
!$
Last argument of previous command
ALT-.
Last argument of previous command
!*
All arguments of previous command
^abc^123
Run previous command, replacing abc with 123

Bash Variables

env
Show enviro­nment variables
Output value of $NAMEvariable
Set $NAME to value
$PATH
Executable search path
$HOME
Home directory
$SHELL
Current shell

IO Redire­ction

cmd < file
Input of cmd from file
cmd1 <(cmd2)
Output of cmd2 as file input to cmd1
cmd > file
Standard output (stdout) of cmd to file
cmd > /dev/null
Discard stdout of cmd
cmd >> file
Append stdout to file
cmd 2> file
Error output (stderr) of cmd to file
cmd 1>&2
stdout to same place as stderr
cmd 2>&1
stderr to same place as stdout
cmd &> file
Every output of cmd to file
cmd refers to a command.

Pipes

cmd1 | cmd2
stdout of cmd1 to cmd2
cmd1 |& cmd2
stderr of cmd1 to cmd2

Command Lists

cmd1 ; cmd2
Run cmd1 then cmd2
cmd1 && cmd2
Run cmd2 if cmd1 is successful
cmd1 || cmd2
Run cmd2 if cmd1 is not successful
cmd &
Run cmd in a subshell

Linux Commands 2

posted Oct 13, 2009, 12:53 AM by JR A

Directory Operations

Show current directory
Make directory dir
Change directory to dir
cd ..
Go up a directory
List files

ls Options

-a
Show all (including hidden)
-R
Recursive list
-r
Reverse order
-t
Sort by last modified
-S
Sort by file size
-l
Long listing format
-1
One file per line
-m
Comma-­sep­arated output
-Q
Quoted output

Search Files

Search for patternin files
grep -i
Case insens­itive search
grep -r
Recursive search
grep -v
Inverted search
grep -o
Show matched part of file only
Find files starting with name in dir
find /dir/ -user name
Find files owned by name in dir
find /dir/ -mmin num
Find files modifed less than numminutes ago in dir
Find binary / source / manual for command
Find file (quick search of system index)

File Operations

Create file1
Concat­enate files and output
View and paginate file1
Get type of file1
Copy file1 to file2
Move file1 to file2
Delete file1
Show first 10 lines of file1
Show last 10 lines of file1
Output last lines of file1 as it changes

Watch a Command

Issue the 'ntpq -p' command every 5 seconds and display output

Process Management

Show snapshot of processes
Show real time processes
Kill process with id pid
Kill process with name name
Kill all processes with names beginning name

Linux Commands 3

posted Oct 13, 2009, 12:52 AM by JR A

Nano Shortcuts

Files
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

Screen Shortcuts

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.

File Permis­sions

Change mode of file to 775
Recurs­ively chmod folder to 600
Change file owner to user and group togroup

File Permission Numbers

First digit is owner permis­sion, second is group and third is everyone.
Calculate permission digits by adding numbers below.
4
read (r)
2
write (w)
1
execute (x)

1-3 of 3