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

Command Line - Cheatsheet: S.N Purpose Command

This document provides a cheat sheet for common Linux command line commands and their purposes. It lists 46 different commands and their definitions, organized by purpose and command. The commands covered include navigating directories, viewing and manipulating files, copying/moving files, searching files, environment variables, and more.

Uploaded by

R. Brown
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)
50 views

Command Line - Cheatsheet: S.N Purpose Command

This document provides a cheat sheet for common Linux command line commands and their purposes. It lists 46 different commands and their definitions, organized by purpose and command. The commands covered include navigating directories, viewing and manipulating files, copying/moving files, searching files, environment variables, and more.

Uploaded by

R. Brown
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/ 10

COMMAND LINE – CHEATSHEET

S.N Purpose Definition Command

1 PRINT WORKING To find out where we are in the file pwd


DIRECTORY system right now

2 LIST List/view the files and directories ls


contained in the current directory

3 HIDDEN FILES All contents, including hidden files and -a


directories

4 LONG FORMAT All contents of a directory in long -l


format, as well as the file permissions

5 TIME Orders files and directories by the time -t


they were last modified

6 LIST ALL OPTIONS All contents, including hidden files and -alt
directories, in long format, ordered by
the date and time they were last
modified

7 CLEAR Clear the terminal of the text after its clear


output

8 LEVEL-UP Navigate one level up to the directory cd ..

9 PARENT DIRECTORY The parent of the current directory .. or ../

10 CURRENT Current directory ./


DIRECTORY

11 DISPLAY CONTENTS Outputs the contents of a specified file cat

12 COPY Command copies files or directories cp

13 COPY FILE1,FILE2 Copy the contents of a source file into cp file1.text file2.txt
a destination file
14 COPY Copy a file to a destination directory cp file.txt directory/
FILE,DIRECTORY

15 COPY To copy multiple files into a directory, cp file1.text file2.txt


FILE1,FILE2,DIRECT source files as the first arguments, directory/
ORY and the destination directory as the
last argument

16 COPY To copy multiple files into a source


SOURCEDIRECTORY directory to destination directory cp directory1/file1.txt
-FILE1, directory2/file2.txt
DESTINATIONDIREC
TORY-FILE2

17 COPY To copy multiple files into a source cp directory1/file1.txt


SOURCE_DIRECTOR directory to destination directory and directory1/file2.txt
Y-FILE1, move to different folder in the directory directory2/
SOURCE_DIRECTOR
Y-FILE2,
DESTINATION_DIRE
CTORY

18 COPY ALL FILES To copy exact filenames as cp * directory/


arguments or select groups of files/
Wildcards are useful for selecting
groups of files and directories

19 COPY EXACT To copy all files in the working cp w*.txt directory/


FILENAMES directory starting with “w” (prefix) and
ending with “.txt” (suffix), and copies
them to directory

20 CHANGE To navigate directly to the directory cd directory1/


DIRECTORY /change directory

21 MAKE DIRECTORY To make a new directory. If a file path mkdir new-directory


is given, the new directory will be
placed at the end or it will create a new
directory in the current working
directory
22 CREATE NEWFILE Creates a new file in the current
working directory with the name touch new-file.txt
provided

23 HELPER COMMANDS Autocomplete the line write first letter Click on

24 HELPER COMMANDS Autocomplete the line Click on


25 MOVE Move a file into a directory. Source file mv file.txt directory/
as the first argument and the
destination directory as the second
argument

26 MOVE FILE1,FILE2 Move the contents of a source file into mv file1.txt file2.txt
a destination file

27 MOVE Move a file to a destination directory mv file1.txt directory/


FILE,DIRECTORY

28 MOVE Move multiple files into a directory, mv file1.txt file2.txt


FILE1,FILE2,DIRECT source files as the first arguments, directory/
ORY and the destination directory as the
last argument

29 MOVE Move multiple files into a source mv directory1/file1.txt


SOURCEDIRECTORY directory to destination directory directory2/file2.txt
-FILE1,
DESTINATIONDIREC
TORY-FILE2

30 MOVE Move multiple files into a source mv directory1/file1.txt


SOURCEDIRECTORY directory to destination directory and directory2/file2.txt
-FILE1, move to different folder in the directory directory2Folder/
DESTINATIONDIREC
TORY - FILE2,
DESTINATIONDIREC
TORY-FOLDER

31 MOVE ALL FILES To move all files in the working mv * directory/


directory / wildcards
32 MOVE EXACT To move exact filenames as mv w*.txt directory/
FILENAMES arguments starting with “w” (prefix)
and ending with “.txt” (suffix), and
copies them to directory

33 REMOVE FILE To delete files. All of its files deleted rm file

34 REMOVE All To delete files and directories. The - rm –r directory


r flag deletes a directory and all of its
files and directories.

35 APPEND REDIRECT >> To redirect the standard output of


SHELL COMMAND the command on the left and append echo "Hello" >> file.txt
it to the end of the file on the right

36 PIPE SHELL | is called a pipe. To transfer, the


COMMAND standard output from the command on echo "Hello" | wc -w
its left into the standard input of the
command on its right.
 echo "Hello" will send Message to the
standard output.
 pipe | will transfer the standard output
to the next command's standard input.
 wc -w will count the number of words
from its standard input, which is 2.

37 REDIRECTING > To redirect output by taking the echo "Hello" > file.txt
OUTPUT output from the command on the left
and passing as input to the file on the
right.

38 CAT DISPLAY To displays the contents of one or cat file.txt


more files to the terminal. cat file1.txt file2.txt

39 GREP SEARCH To search files for lines that match a grep ‘hello’ file.txt
pattern and returns the results.
 The lines in the file file.txt which
contain “hello” will be returned.
40 CASE INSENSITIVE -i can be used to search files for lines grep -i XXX
SEARCH that match a pattern, case insensitive continents.txt
and returns the results.
 grep searched for
capital or lowercase strings
that match “XXX”
in continents.txt

41 GREP –R (recursive) -R that searches all files in a directory,


SHELL COMMAND including its subdirectories, and OP
filenames and lines containing
matched results.

42 COMMAND LINE The process of using the IP/OP of a ls > file.txt


REDIRECTION file or command to use it as an IP for ls >> file.txt
another file. It is similar but different
from pipes, it allows RD/WR from files
instead of only commands.
 Redirection can be done by
operators > and >>

43 COMMAND LINE It refers to settings and preferences of environment


ENVIRONMENT the current user. It enables users to
set greetings, alias commands,
variables, and much more
 Environment Variables that can
be used across terminal
commands.
 They hold information about
the shell’s environment.

44 USER Unix-based systems like Mac OS and env


ENVIRONMENT Linux, this returns a list of environment
VARIABLES variables for the current user.

45 ALIAS To assign commonly used commands


to shortcuts. The assigned commonly
used command should be wrapped in alias pd="pwd"
double quotes.
 The following command creates an
alias `pd` for the command `pwd`

46 SOURCE BASH All the commands source ~/.bash_profile


PROFILE in ~/.bash_profile are executed with
the shell command.
 When changes are made
to ~/.bash_profile, run this
command to activate the
changes in the current session

47 HISTORY COMMAND To get a history of events that were history


executed in the current session.
 To perform operations on this
list of commands that have
been executed, such as
selecting or manipulating a
command in the history.

48 EXPORT COMMAND The given variable available to all child export USER="ALEXA"
sessions initiated from the current
session export USER="Jane
 This command will make the Doe"
environment variable: USER
available
 To all child sessions with the
value "ALEXA"

49 HOME ENVIRONMEN It is used to get the path to the current


T VARIABLE IN UNIX user’s home directory or to access the echo $HOME
SYSTEMS home directory when needed.

50 CONTENT Output of cat volcanoes.txt becomes


the standard input of wc. in turn, cat file.txt | wc
the wc command outputs the number
of lines, words, and characters
in volcanoes.txt, respectively
51 CONTENT Multiple | can be chained together. cat file1.txt | wc | cat >
The standard output of cat file1.txt is file2.txt
“piped” to the wc command. The
standard output of wc is then “piped”
to cat. Finally, the standard output
of cat is redirected to file2.txt.

52 SORT sort takes the standard input and sort file.txt


orders it alphabetically for the
standard output (it doesn’t change the
file itself)

53 UNIQ uniq stands for “unique.” It filters out uniq file.txt


adjacent, duplicate lines in a file.

SORT UNIQ file uniq is to call sort to alphabetize a file, sort file.txt | uniq
and “pipe” the standard output to uniq.
By piping sort file.txt to uniq, all
duplicate lines are alphabetized (and
thereby made adjacent) and filtered
out.

55 SORT UNIQ file,file Sending filtered contents to uniq- Sort file.txt |uniq-file.txt
file.txt, To view with the cat command.

56 QNIQ-NO DUPLICATE To create a new file named uniq- Sort file.txt | uniq>uniq-
file.txt that contains a sorted version file.txt
of file.txt with no duplicates.

57 SEARCH sed stands for “stream editor.” It Sed ‘s/bats/rats/’file.txt


accepts standard input and modifies it
based on an expression, before
displaying it as output data. It is similar
to “find and replace.
 sed searches file.txt for the word
“bats” and replaces it with “rats”
Importantly, the above command
will only replace the first instance
of “bats” on a line.
 s: Stands for “substitution.” It
is always used sed for
substitution.
 bats: Search string, or the text to
find.
 rats: Replacement string, or the
text to add in place.

58 SEARCH g expression,meaning“global.” sed sed ‘s/bats/rats/g’ file.txt


searches file.txt for the word “bats”
and replaces it with “rats” globally.
This means all instances of “bats” on
a line will be turned to “rats”
 sed will only rewrite the command
line output and the actual file won’t
be changed

59 REWRITE In order to rewrite the actual file, we sed -i 's/bats/rats/g’


need to use -i at the beginning of the file.txt
command.
 Rewritefile.txt andreplace all
Instances (since we’re also
using g) of “bats” with “rats”.

60 SAVE To save the file Ctrl + O

61 EXIT To exit the nano program. X stands for Ctrl + X


exit

62 HELP To open a help menu Ctrl + G

63 HARD EXIT Having trouble in nano and need to Ctrl + C


exit

64 FORCE EXIT Having trouble in nano and need to Ctrl + Z or F2


force-exit
65 BASH PROFILE File used to store environment ~/.bash_profile
settings for terminal, and it’s
accessible by the name
 ~ represents the user’s home
directory.
 . Indicates a hidden file.
 ~/.bash_profile is important, since
this is how the command line
recognizes the bash profile.

66 OPEN BASH To open and edit the bash profile nano ~/.bash_profile

67 ECHO If we have an echo statement in the echo


bash profile, that will echo when a
terminal session begins.

68 EDIT BASH To activate the changes made source ~/.bash_profile


in ~/.bash_profile for the current
session

69 ALIAS Add settings and commands that Alias pd =”pwd”


execute every time a new terminal
session is started. It is a type of setting
you can create is called an alias
 Alias command allows you to
create keyboard shortcuts, or
aliases, for commonly used
commands

You might also like