Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

BASH Command Cheat Sheet, Cheat Sheet of Computer Programming

Command, description, quit and example table for bash commands

Typology: Cheat Sheet

2020/2021

Uploaded on 04/23/2021

ekansh
ekansh 🇺🇸

4.3

(20)

266 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
BASH Cheat Sheet
2017 ICOS Big Data Summer Camp
Most BASH commands
follow the pattern $[command][options][input][output]
tell you how to use them if you type $[command]--help
have a manual file with more info $man[command]
are explained with examples if you google them “bash [command] example”
Command
Description
Quit
Example
!!
Repeat the previous command.
cat
Concatenate. Takes the contents of a file and
puts them on the end of something else (your
screen, another file, etc.)
[ctrl]+C
catfile.txt
cd
Change Directory. Move from one folder
(directory) to another.
cdmy_folder/data
cp
Copy. Make a copy of a file. See also: mv.
[ctrl]+C
cporiginal.htmlcopy.html
diff
Difference. Print a list of all lines that are different
between two files.
[ctrl]+C
diffold.csvnew.csv
echo
Echo. Repeat whatever I type next.
echo"Hello,World!"
emacs
Editor Macros. Program for editing files.
Advanced users. See also: vi, nano, pico.
find
Find. Search for files that match some criteria
(size, date modified, name, type, and more).
[ctrl]+C
find.-name"*.html"-size+100k
grep
Search for lines of text that match a pattern and
print them (similar to [ctrl]+F or [cmd]+F). See
also: sed.
[ctrl]+C
grep“href”kitten.html
head
Print just the top (head) of a file. See also: tail.
[ctrl]+C
headlong_file.txt
htop
Hisham Table of Processes. Like "top", but with
more information and colors.
[ctrl]+C
htop
ll
List Long. The same as "ls -l". Will show the size,
owner, date, and permissions for all files in the
current directory.
[ctrl]+C
ll-h
ls
List files in the current directory.
[ctrl]+C
ls
man
Manual. Show the manual entry for a command
to see how to use it and what the options are.
(Use arrow keys to scroll.)
Q
mancat
mkdir
Make Directory. Create a new directory (folder).
See also: rmdir.
mkdirnew_folder
mv
Move a file or directory. See also: cp.
[ctrl]+C
mvfile.txtsubfolder/file.txt
nano
Same as "pico" but released as free software.
[ctrl]+X
nanomy_code.py
pico
Pine Composer. Very simple program for editing
files in the terminal. See also: vi, nano, emacs.
[ctrl]+X
picomy_code.py
pf2

Partial preview of the text

Download BASH Command Cheat Sheet and more Cheat Sheet Computer Programming in PDF only on Docsity!

BASH Cheat Sheet

2017 ICOS Big Data Summer Camp

Most BASH commands

● follow the pattern $ [command] [options] [input] [output]

● tell you how to use them if you type $ [command] --help

● have a manual file with more info $ man [command]

● are explained with examples if you google them “bash [command] example”

Command Description Quit Example !! Repeat the previous command.

cat

Concatenate. Takes the contents of a file and puts them on the end of something else (your screen, another file, etc.)

[ctrl]+C cat file.txt

cd Change Directory. Move from one folder (directory) to another. cd my_folder/data

cp Copy. Make a copy of a file. See also: mv. [ctrl]+C cp original.html copy.html

diff Difference. Print a list of all lines that are different between two files. [ctrl]+C diff old.csv new.csv

echo Echo. Repeat whatever I type next. echo "Hello, World!"

emacs Editor Macros. Program for editing files. Advanced users. See also: vi, nano, pico.

find Find. Search for files that match some criteria (size, date modified, name, type, and more). [ctrl]+C^ find. -name "*.html" -size +100k

grep

Search for lines of text that match a pattern and print them (similar to [ctrl]+F or [cmd]+F). See also: sed.

[ctrl]+C grep “href” kitten.html

head Print just the top (head) of a file. See also: tail. [ctrl]+C head long_file.txt

htop Hisham Table of Processes. Like "top", but with more information and colors. [ctrl]+C htop

ll

List Long. The same as "ls -l". Will show the size, owner, date, and permissions for all files in the current directory. [ctrl]+C

ll -h

ls List files in the current directory. [ctrl]+C ls

man

Manual. Show the manual entry for a command to see how to use it and what the options are. (Use arrow keys to scroll.)

Q man cat

mkdir Make Directory. Create a new directory (folder). See also: rmdir. mkdir new_folder

mv Move a file or directory. See also: cp. [ctrl]+C mv file.txt subfolder/file.txt nano Same as "pico" but released as free software. [ctrl]+X nano my_code.py

pico Pine Composer. Very simple program for editing files in the terminal. See also: vi, nano, emacs. [ctrl]+X^ pico my_code.py

Command Description Quit Example

pwd Print Working Directory. Show the full path of what directory (folder) you are currently in. pwd

rm

Remove. Deletes the specified file(s). Does not send things to a trash folder. They are gone forever.

[ctrl]+C rm unwanted_file.doc

rmdir Remove Directory. Deletes a specified directory/folder. See also: mkdir. [ctrl]+C rmdir unwanted_directory

script

Make a record of everything that I type and everything that appears in my terminal until I type "exit." Then save that as a file.

"exit"

sed

Stream Editor. The sed command can do a lot, but it's most useful function is find and replace in text. See also: grep.

[ctrl]+C sed 's/dog/cat/g' dog.txt > cat.txt

split Splits a file into multiple smaller files. See also cat, which can put them back together. [ctrl]+C split big_file.csv

ssh Secure Shell. Connect to a remote server's command line. "exit" ssh my.server.umich.edu

tail Print just the bottom of a file. See also: head. [ctrl]+C tail long_file.txt

top

Table Of Processes. Shows running processes memory use. Like WIndows system monitor or Mac activity monitor. See also: htop.

[ctrl]+C top

uname Unix Name. Print the name and versio n of my operating system. uname -a

vi

Visual (line editor). A program for editing files in the terminal. Intermediate and advanced users. See also: pico, nano, emacs.

[esc]+[:]+Q vi my_code.py

wc Word Count. Count many lines, words, and characters are in something. [ctrl]+C wc essay.txt

wget Web Get. Download something from an internet URL. [ctrl]+C wget bbc.co.uk

Symbol Use


Wildcard. Select everything. Can be combined with other characters, e.g. "*.txt" would match all files ending in ".txt" and "ls *.txt" will list the files that end in ".txt".

> Overwrite. Take the output of the argument to the left and use it to replace the contents of what is on the right. E.g. "cat updates.txt > latest.txt" will replace whatever is in 'latest.txt' with whatever is in 'updates.txt'.

>> Append. Take the output of the argument to the left and add it to end end of what is on the right. E.g. "cat updates.txt >> all.txt" will add whatever is in 'updates.txt' to the end of ‘all.txt' after what is already in there.

Pipe (usually above the [enter] key). Use the output of the command to the left as input for the command to the right. E.g. in order to count the files in a directory, you can type "ls | wc -l". ls outputs a list of files, one per line. That list is sent ("piped") to the word count utility with the "-l" option to count lines. The result is the count of files.

; End previous command, begin a new one. E.g. “echo “We’re in”; pwd” would first print the words “We’re in” and then it would print the path of the current working directory.