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

Linux Command Line Cheat Sheet

This document provides a summary of various Linux commands and shortcuts for the Bash shell, file operations, the Nano text editor, searching files, and using the Screen terminal multiplexer. It includes commands for system information, directories, file manipulation, grepping, finding files, Bash variables, and shortcuts for Bash, Nano, and Screen. The document is intended as a quick reference cheat sheet for common Linux tasks.

Uploaded by

belopezp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Linux Command Line Cheat Sheet

This document provides a summary of various Linux commands and shortcuts for the Bash shell, file operations, the Nano text editor, searching files, and using the Screen terminal multiplexer. It includes commands for system information, directories, file manipulation, grepping, finding files, Bash variables, and shortcuts for Bash, Nano, and Screen. The document is intended as a quick reference cheat sheet for common Linux tasks.

Uploaded by

belopezp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

 Kitchen, Audio

e.g., Regular Expressions, Garden,    

LOGIN or REGISTER

 Home  Cheat Sheets  Create  Community  Help

 Download This Cheat Sheet (PDF)  66 Comments Rating:      (283) 

Home > Software > Linux Cheat Sheets

Linux Command Line Cheat Sheet by DaveChild


A cheat sheet of the commands I use most for Linux, with popup links to man pages.

Bash Commands Directory Operations

uname -a Show pwd Show current directory


system and mkdir dir Make directory dir
kernel
cd dir Change directory to dir
head -n1 /etc/issue Show distri-
cd .. Go up a directory
bution
ls List files
mount Show
mounted
filesystems
ls Options
date Show
system date -a Show all (including hidden)

uptime Show -R Recursive list

uptime -r Reverse order

whoami Show your -t Sort by last modified


username -S Sort by file size
man command Show -l Long listing format
manual for
-1 One file per line
command
-m Comma-separated output

-Q Quoted output
Bash Shortcuts Search Files Nano Shortcuts

CTRL-c Stop current grep pattern files Search Files


command for Ctrl-R Read file
CTRL-z Sleep program pattern in
Ctrl-O Save file
files
CTRL-a Go to start of line Ctrl-X Close file
grep -i Case
CTRL-e Go to end of line Cut and Paste
insens-
CTRL-u Cut from start of line itive ALT-A Start marking text
CTRL-k Cut to end of line search
CTRL-K Cut marked text or line
CTRL-r Search history grep -r Recursive
CTRL-U Paste text
search
!! Repeat last command Navigate File
grep -v Inverted
!abc Run last command ALT-/ End of file
search
starting with abc
CTRL-A Beginning of line
grep -o Show
!abc:p Print last command
matched CTRL-E End of line
starting with abc
part of file CTRL-C Show line number
!$ Last argument of
only
previous command CTRL-_ Go to line number
find /dir/ -name name* Find files
ALT-. Last argument of Search File
starting
previous command CTRL-W Find
with
!* All arguments of name in ALT-W Find next
previous command dir
CTRL-\ Search and replace
^abc^123 Run previous find /dir/ -user name Find files
More nano info at:
command, replacing owned by
http://www.nano-editor.org/doc-
abc with 123 name in
s.php
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)
Bash Variables File Operations Screen Shortcuts

env Show touch file1 screen


enviro- Create file1 Start a screen session.
nment
cat file1 file2 screen -r
variables
Concatenate files and output Resume a screen session.
echo $NAME Output
value of less file1 screen -list
$NAME
View and paginate file1 Show your current screen
variable
sessions.
file file1
export NAME=value Set
Get type of file1 CTRL-A
$NAME to
value Activate commands for screen.
cp file1 file2
$PATH Executable Copy file1 to file2 CTRL-A c
search Create a new instance of
mv file1 file2
path terminal.
Move file1 to file2
$HOME Home
CTRL-A n
directory rm file1
Go to the next instance of
$SHELL Current Delete file1
terminal.
shell
head file1
CTRL-A p
Show first 10 lines of file1
Go to the previous instance of
tail file1 terminal.

Show last 10 lines of file1 CTRL-A "

tail -F file1 Show current instances of


terminals.
Output last lines of file1 as it
changes CTRL-A A

Rename the current instance.

Watch a Command More screen info at:


http://www.gnu.org/software/sc-
watch -n 5 'ntpq -p' reen/
Issue the 'ntpq -p' command
every 5 seconds and display
File Permissions
output

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
IO Redirection Process Management File Permission Numbers

cmd < file ps Show snapshot of First digit is owner permission,

Input of cmd from file processes second is group and third is

top Show real time everyone.


cmd1 <(cmd2)
processes Calculate permission digits by
Output of cmd2 as file input to
kill pid Kill process with id adding numbers below.
cmd1
pid 4 read (r)
cmd > file
pkill name Kill process with 2 write (w)
Standard output (stdout) of name name 1 execute (x)
cmd to file
killall name Kill all processes
cmd > /dev/null with names

Discard stdout of cmd beginning name

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

 bash  nano  linux  ls  commandline  ubuntu  server

 sysadmin  shell

Download the Linux

Command Line Cheat Sheet

PDF (recommended)

 PDF (2 pages)

Alternative Downloads

 PDF (black and white)


 LaTeX

2 Pages
Comments Created By

[deleted], 10:02 28 Nov 11 DaveChild


https://aloneonahill.com

Thanks for creating this cheat-sheet Dave. The one thing I missed was
"grep -o"; Show only the part of a matching line that matches PATTERN

DaveChild, 10:02 28 Nov 11

Metadata
I've added "grep -o" to the cheat sheet :)

Languages: English

a_statham, 10:02 28 Nov 11 Published: 28th October, 2011

Last Updated: 29th February,

The I/O redirection section could use "2>" and "&>" examples, I always 2020

forget how to redirect stderr Rated: 5 out of 5 stars based on


283 ratings

DaveChild, 10:02 28 Nov 11

I've updated that section to include stderr redirection. :)

Favourited By
DaveChild, 10:02 28 Nov 11

Good idea - I'll add that (once I remember how they work myself
... :) )

wattslevi, 19:51 29 Nov 11

and 388 more ...


How are the indented lines added several of the cells like Screen Shortcuts?
RE: http://getsatisfaction.com/cheatography/topics
/adding_a_two_line_entry_in_a_list
DaveChild, 08:35 30 Nov 11

Those indented bits are a "question and answer" format box.

wattslevi, 10:30 30 Nov 11

Ah, Q&A means I would be able to cheat with it and use it for
two column with an extra line. Thanks for the info.

(Replying to my original post seems unintuitive for trying to reply


under your post, but not to the overall thread... assuming this
post as I'm thinking it might.)

jim 23:12 30 Nov 11

On the redirects, the one I most commonly use is ignoring errors (2>/dev
/null, or more succinctly 2>&- ).

For example, if I'm looking for files and I don't care that I haven't access to
parts of the filesystem, we might do something like:

find / -name "*.html" 2>&-

Tanner 10:30 7 Mar 12

ls -h is handy - changes sizes to human readable formats. Goes along good


with -S. If I'm using it it is generally a ls -alhS

Wane 07:28 21 Mar 12

I think the "Bash Shortcuts" part is a little misleading. The "ctrl-a", "ctrl-e",
"ctrl-k" is in emacs mode. But there should be many people preferring vim-
mode or some thing like that.
Davis Peng 13:57 22 Mar 12

Thanks a lot for your sheet, I just need such a linux command summary
such as this sheet.

gamiclea, 00:05 2 Jun 12

Awesome job! This will definitely come in handy

wolvverine 11:29 6 Jun 12

download PDF is broken

Arpit 10:51 29 Jun 12

Good work. Thanks, its helpful.

Chetan Morajkar 14:35 6 Aug 12

Hi,

Fantastic good job..

Thanks

Donald J. Tambeau 15:23 6 Aug 12

Love your work....it is so ....so helpful! I would like to format a MicroDisk


using Linux Centros. When I look at the Partition on the MicroDisk, I see the
following comment....(non-Linux). This makes sense, since I formatted with
a computer running Win 7! I want to use it on my Linux system but do not
know how to do it. I tried format /dev/scd1 but no joy!
Thank you
Don
Eric 08:59 7 Aug 12

I'd just like to point out a trick I use with the head and tail commands:
First, you can designate the number of lines to return, like so: head -100
filename
I often use both head and tail together to get a section of a file by piping the
output of one into the other. The following command gets 100 lines, starting
1000 lines before the end of the file:
tail -1000 filename | head -100
You could, of course, reverse the commands to get a section near the top of
the file. To get lines 91-100:
head -100 filename | tail -10

Mark 08:53 29 Aug 12

I just wanted to take a moment to thank you for putting this together. This is
a big help to me I am new to OpenFiler witch I believe uses bash at the core
so I am of course new to Linux. I didn't really think it would be quite so
difficult to find resources that one can use to navigate the command line but
I guess most folks use the GUI. But, I'm not most folks when I bought my
first IBM 8088 I started with DOS.Anyway, thanks for the time and effort you
put into this, sorry about digressing there.

Shrinath 13:08 4 Oct 12

Excellent Stuff man.. I think these are the most commonly used commands..
Good Effort.

JImmy 21:43 11 Oct 12

you need to figure out how to split your command sheet as a pdf

Niloufar 21:43 11 Oct 12

hi!.these are useful cheat sheet .


russ 16:18 22 Oct 12

CTRL-Z sleeps (stops) the running process. fg [#] brings it back to


foreground.

top
CTRL-Z
ps aux | grep top
fg

chiahsun 11:14 2 Jan 13

Show human readable format (kb, mb...)


ls -lh

PierreBdR, 11:35 9 Feb 13

This cheat-sheet is very good! Thanks for that.

However, I don't like the "chmod" commands you are using. I don't think
anybody should use the numeric version of chmod anymore. Your example
"chmod -R 600 folder", is the best way to lock yourself out of your own folder
and loose any executable bits on the scripts. I would rather use the symbolic
version:

chmod -R u+rw folder # Add read-write for user on all files in folder
chmod -R og-rwx # Remove read write and execute bits for "other" and
"group" on all files in folder

And my all-time favorite:

chmod -R og=u-w folder # Give other and group the same rights as user, but
removing writing rights.

Of course, this also handles t and s bits:

chmod u+s file


chmod o+t folder
Stylius 09:17 15 Feb 13

I would also add the tar command. No sysadmin would survive without it.

To extract tar.gz archive


tar xvzf archive.tar.gz

To extract tar.bz2 archive


tar xvjf archive.tar.bz2

To extract tar archive


tar xvf archive.tar

To create archive
tar cvzf archive.tar.gz /file_or_folder/to/archive

Sandeep 08:43 16 Feb 13

Nice one...really helpful

John 08:43 16 Feb 13

Great resource - thanks for taking the time and trouble to put this out there.

My favorite ls options are '-ltr' . The t sorts files by time, and r reverses that,
so newest files show up right above the prompt, no matter how long the
listing is.

daveydave400 08:43 16 Feb 13

What about CTRL+y to paste the stuff you cut back in? How can you leave
that out? CTRL+a/e and CTRL+u/y are the pairs I remember.

gymka 08:44 16 Feb 13


Missing: sed
find -exec

Jared 10:33 26 Feb 13

Nice work, but it would be best as a single page PDF.

Darr247 16:31 5 Apr 13

Or if the PDF at least split into 2 pages (so it could be a laminated 2-sided
sheet) without cutting commands in half.

PastExpiryDotCom, 18:08 11 Jul 13

This is bash-tastic!

kimcy929, 11:09 9 Aug 13

thank you very much, it is great

Pradeep 15:12 13 Feb 14

There is no commands for shutdown or reboot..

RobertAttfieldDotCom 11:37 14 Feb 14

Good job on the cheatsheet - this will definitely come in handy for my Linux
exam next week. Some commands on umask would be a good addition to
this cheatsheet :).
Bill 17:30 17 Feb 14

Hi, handy sheet. Just one thing. Find will do a recursive search by default. In
the find /dir -name name* should be in double quotes if you want it to
recursively find all files starting with name:

find /dir/ -name "name*"

That's because, without the quotes, the shell will expand the wildcard before
handing the parameters to find. To unexpected things might happen if you
don't have the quotes. Please see the examples below:

$ find .
.
./name1
./name2
./dir1
./dir1/name3
./dir1/name1
./dir1/test3
./test1
$ find . -name name*
find: paths must precede expression: name2
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec]
[path...] [expression]
$ find . -name "name*"
./name1
./name2
./dir1/name3
./dir1/name1
$ touch dir1/fred1
$ find .
.
./name1
./name2
./dir1
./dir1/name3
./dir1/name1
./dir1/test3
./dir1/fred1
./test1
$ find . -name name*
find: paths must precede expression: name2
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec]
[path...] [expression]
$ find . -name "name*"
./name1
./name2
./dir1/name3
./dir1/name1
$ find . -name fred*
./dir1/fred1
$ find . -name "fred*"
./dir1/fred1
$

Edser 17:35 17 Feb 14

grep -B#

This shows what you are searching plus additional lines where number is
added. Great for DHCP lease searching.

No4711 09:56 19 Feb 14

I would suggest to put in screen <tty.device> <baudrate> – just in case


anybody needs to connect to some serial console…

Henning 09:57 19 Feb 14

Great reference!
The section on Screen is missing "Ctrl-A d" for detaching.

Mads 08:55 26 Feb 14

Great resource - thanks a lot Dave!

Kabir 22:03 10 Mar 14

add task manage comman:


gnome-system-monitor
Isabel Ambriz 13:08 30 Apr 14

Command that might be used to test connectivity of Linux box to the


Internet, get logged on user info, and get TCP/IP configuration info. Can
anyone help me?

Aaron Tani 08:27 1 May 14

theres also a good one here: http://www.techietek.com/2014/04/29/linux-cli-


cheat-sheet-wallpaper/

Damien 10:43 23 Jul 14

I've always found `mkdir -p path/to/directory` to be useful.

snakeroot 10:46 14 Jan 15

head -n1 /etc/issue as a means to access distribution name isn't reliable,


since the post-login screen could have been customized.

A more reliable version would be sed -nr 's/^PRETTY_NAME=(.*)/\1/p'


/etc/os-release . This should be true even for distros using legacy init (i.e.,
current Debian, Gentoo and even Slackware).

jt 12:38 22 Jul 15

ls -h? human readable?

DF 08:31 25 Aug 15

would be good to add Ctrl-left/right for jumping arguments, Ctrl-home/end


for jumping whole line.
Alex 15:34 28 Sep 15

'echo $SHELL' actually prints the default shell, 'ps -p $$' will print the current
shell

John Kershaw 16:04 28 Mar 16

Love the colour, but could it be a slightly darker/stronger green? It comes


out almost impossible to read on my colour printer. I tried outputting in
greyscale, but the green-on green sections are still unreadable. Needs more
contrast.

Alternatively, change all the green texts to black and keep the backgrounds
green?

DaveChild, 16:05 28 Mar 16

I agree, it's not a great colour. I've changed it.

Felipe 19:22 3 Apr 16

Could you add "passwd" to the file? :)

GloObi, 15:31 4 Apr 16

thank you for this really useful sheet !

The download button seems to be broken though :(

NatalieMoore, 05:13 10 Apr 16

Hey GloObi, thanks for the heads up about the broken download
button on this cheatsheet. We'll get it fixed and I'll let you know
when its been done. Have a great day.

NatalieMoore, 06:49 13 Apr 16

Hi GloObi,

This is now fixed. Please let me know if you have any more
problems.

Nat

d.falkovsky, 19:54 7 Apr 16

Can't download. Sad.

NatalieMoore, 05:07 10 Apr 16

Thanks d.falkovsky, I will let Dave know the download button on


this cheat sheet needs to be fixed. I will let you know once he
has fixed it :). Sorry for the inconvenience.

NatalieMoore, 06:48 13 Apr 16

Hi d.falkovsky,

This is now fixed, you should now be able to download. Please


let me know if you have any more problems.

Nat

d.falkovsky, 13:15 16 Apr 16

Thank you, Natalie!


ramiissat, 13:01 22 Mar 17

Good job Dave, Thank you :)

tejasshetty.1808, 18:51 8 Jul 17

I think the colour pdf link directs back to the original page

wkthxtn, 21:34 7 Nov 18

Good for quick reference Thank you

hwac121, 06:53 13 Dec 18

All links for download are dead, pleas fix this issue ASAP. Would be greatly
appreciated, thanks.

Chinaguravaiah M, 05:32 13 Sep 19

thank you very much Dave

grantiago, 14:27 17 Jan 21

thanks Dave
besides ^w my most used nano commands:
Alt+Space Go back one word
Ctrl+Space Go forward one word

Sathyanarayanan, 03:44 19 Oct 21

check this sheet!


https://cheatography.com/sathyanarayanan/cheat-sheets/linux-command-
line/

Add a Comment

Your Comment

Your Name

Your Email
Address

Your Comment

Post Your Comment

Related Cheat Sheets



Linux, Bash, and System


Administration Cheat Linux Every Day
mod_rewrite Cheat Sheet Sheet Commands Cheat Sheet
More Cheat Sheets by DaveChild

  

Regular Expressions
Cheat Sheet CSS2 Cheat Sheet mod_rewrite Cheat Sheet

Latest Cheat Sheet Random Cheat Sheet

Anatomy and Assessment


Physiology-Urinary Checklist Cheat
System Cheat Sheet
Sheet General Assessment

A brief overview of the urinary harpieee


system  1 Dec 18, updated 4 Jan 19
 8 Pages  1 Page
 medical, healthcare,
Cocobaby927
     (0)      (1) -cheatsheet, -assessment, -nursing
 1 Dec 23
 nursing, anatomy, urinary,
renal

About Cheatography Behind the Scenes Recent Activity


Cheatography is a collection of 6212 If you have any problems, or just want CROSSANT updated
cheat sheets and quick references in to say hi, you can find us right here: Calculus II.
25 languages for everything from 7 hours, 1 min ago
food to history! himajedi updated Censys
DaveChild
Search.

SpaceDuck 20 hours 50 mins ago

Cocobaby927 published
Cheatography Anatomy and Physiology-
Urinary System.
2 days 7 hours ago

© 2011 - 2023 Cheatography.com | CC License | Terms | Privacy  Latest Cheat Sheets RSS Feed

You might also like