Docsity

Linux Command Line - Principais comandos para o terminal Linux, Esquemas de Sistemas Operacionais

Toggle sidebar
bg1
Linux Command Line Cheat Sheet
by Dave Child (DaveChild) via cheatography.com/1/cs/49/
Bash CommandsBash Commands
uname -a Show system and
kernel
head -n1 /etc/issue Show distribution
mount Show mounted filesy‐
stems
date Show system date
uptime Show uptime
whoami Show your username
man
command
Show manual for
command
Bash ShortcutsBash 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 with
abc
!
abc
:p Print last command starting
with
abc
!$ 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 VariablesBash Variables
env Show environment
variables
echo
$NAME
Output value of
$NAME
variable
Bash Variables (cont)Bash Variables (cont)
export
NAME
=
value
Set
$NAME
to
value
$PATH Executable search
path
$HOME Home directory
$SHELL Current shell
IO RedirectionIO 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.
PipesPipes
cmd1
|
cmd2
stdout of
cmd1
to
cmd2
cmd1
|&
cmd2
stderr of
cmd1
to
cmd2
Command ListsCommand 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
Directory OperationsDirectory Operations
pwd Show current directory
mkdir
dir
Make directory
dir
cd
dir
Change directory to
dir
cd .. Go up a directory
ls List files
ls Optionsls 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 FilesSearch Files
grep
pattern
files
Search for
pattern
in
files
grep -i Case insensitive
search
grep -r Recursive search
grep -v Inverted search
grep -o Show matched
part of file only
find
/dir/
-name
name
*Find files starting
with
name
in
dir
By Dave ChildDave Child (DaveChild)
cheatography.com/davechild/
aloneonahill.com
Published 28th October, 2011.
Last updated 29th February, 2020.
Page 1 of 2.
Sponsored by CrosswordCheats.comCrosswordCheats.com
Learn to solve cryptic crosswords!
http://crosswordcheats.com
pf2

Pré-visualização parcial do texto

Baixe Linux Command Line - Principais comandos para o terminal Linux e outras Esquemas em PDF para Sistemas Operacionais, somente na Docsity!

Linux Command Line Cheat Sheet

by Dave Child (DaveChild) via cheatography.com/1/cs/49/

Bash Commands Bash Commands uname -a Show system and kernel head -n1 /etc/issue Show distribution mount Show mounted filesy‐ stems date Show system date uptime Show uptime whoami Show your username

man command Show manual for

command

Bash Shortcuts 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 with

abc

! abc:p Print last command starting

with abc

!$ 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 Bash Variables env Show environment variables

echo $NAME Output value of $NAME

variable Bash Variables (cont) Bash Variables (cont)

export NAME= value Set $NAME to value

$PATH Executable search path $HOME Home directory $SHELL Current shell IO Redirection IO Redirection

cmd < file

Input of cmd from file

cmd1 <( cmd2)

Output of cmd2 as file input to cmd

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>&

stdout to same place as stderr

cmd 2>&

stderr to same place as stdout

cmd &> file

Every output of cmd to file

cmd refers to a command.

Pipes Pipes

cmd1 | cmd

stdout of cmd1 to cmd

cmd1 |& cmd

stderr of cmd1 to cmd

Command ListsCommand Lists

cmd1 ; cmd

Run cmd1 then cmd

cmd1 && cmd

Run cmd2 if cmd1 is successful

cmd1 || cmd

Run cmd2 if cmd1 is not successful

cmd &

Run cmd in a subshell

Directory OperationsDirectory Operations pwd Show current directory

mkdir dir Make directory dir

cd dir Change directory to dir

cd .. Go up a directory ls List files ls Optionsls 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-separated output -Q Quoted output Search FilesSearch Files

grep pattern files Search for pattern

in files

grep -i Case insensitive search grep -r Recursive search grep -v Inverted search grep -o Show matched part of file only

find /dir/ -name name* Find files starting

with name in dir

By Dave ChildDave Child (DaveChild) cheatography.com/davechild/ aloneonahill.com Published 28th October, 2011. Last updated 29th February, 2020. Page 1 of 2. Sponsored by CrosswordCheats.comCrosswordCheats.com Learn to solve cryptic crosswords! http://crosswordcheats.com

Linux Command Line Cheat Sheet

by Dave Child (DaveChild) via cheatography.com/1/cs/49/

Search Files (cont) Search Files (cont)

find /dir/ -user name Find files owned by

name in dir

find /dir/ -mmin num Find files modifed

less than num

minutes ago in dir

whereis command Find binary / source /

manual for command

locate file Find file (quick

search of system index) File Operations File Operations

touch file

Create file

cat file1 file

Concatenate files and output

less file

View and paginate file

file file

Get type of file

cp file1 file

Copy file1 to file

mv file1 file

Move file1 to file

rm file

Delete file

head file

Show first 10 lines of file

tail file

Show last 10 lines of file

tail -F file

Output last lines of file1 as it changes

Watch a Command Watch a Command watch -n 5 'ntpq -p' Issue the 'ntpq -p' command every 5 seconds and display output Process Management Process Management ps Show snapshot of processes top Show real time processes

kill pid Kill process with id pid

pkill name Kill process with name name

killall name Kill all processes with names

beginning name

Nano Shortcuts Nano Shortcuts Files Files Ctrl-R Read file Ctrl-O Save file Ctrl-X Close file Cut and Paste Cut and Paste ALT-A Start marking text CTRL-K Cut marked text or line CTRL-U Paste text Navigate File 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 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 Shortcuts screen Start a screen session. screen -r Resume a screen session. Screen Shortcuts (cont)Screen Shortcuts (cont) 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/ File PermissionsFile Permissions

chmod 775 file

Change mode of file to 775

chmod -R 600 folder

Recursively chmod folder to 600

chown user: group file

Change file owner to user and group to

group

File Permission NumbersFile Permission Numbers First digit is owner permission, second is group and third is everyone. Calculate permission digits by adding numbers below. 4 read (r) 2 write (w) 1 execute (x) By Dave ChildDave Child (DaveChild) cheatography.com/davechild/ aloneonahill.com Published 28th October, 2011. Last updated 29th February, 2020. Page 2 of 2. Sponsored by CrosswordCheats.comCrosswordCheats.com Learn to solve cryptic crosswords! http://crosswordcheats.com