My CLI cheat sheet
This is my CLI cheat sheet of the commands I most frequently use
List
ls
- list filesls - a
list all including hidden filesls - l
list long versionls - la
orls -lah
list all including hidden files in long versionls - s
list and sortls -lt
list long and sort by modification time - newest firstls | less
- list a shorter version (uses the pipe symbol)ls a*
- files starting with a (uses the wild card asterisk to search)ls *a
- files ending with a (uses the wild card asterisk to search)ls *amperstand*
- files with amperstand anywhere in the files (see grep as well)ls -t
- order in which changednpm ls -g --depth 0
list all npm packages
Print and list
pwd
- print working directoryecho $PATH
- prints current path. Your default path should be export PATH=/usr/bin:/usr/sbin:/bin:/sbinecho *
prints all the files in the directory (star is a wild card finder)
Sort
b
- ignore blanksls -s -r
- list sort reverse order
Create
mkdir <directory names space delineated>
make directories with a space inbetweenmkdir -p <path/directories>
make directories and subdirectories in a single pathtouch <filename>
make a new file in the directory if you have spaces between file names you will have as many files as there are spaces eg:touch this is my file
- will create this/is/my/file as separate files.cat this \ is \ my \file
concatinates files into one file - you will get a file withas the file name echo
prints to consolenano create_report
for nano editors
Copy
cp [~/filepathfrom ~/filepathto]
copy file from one directory to anothercp [~/*.file-extension ~/filepathto]&
copy all files with the file extension (eg..doc/.jpg
) from one directory to another#
Comments - non-executable as code
Navigate or move files/directories/shells
cd
change directorycd..
move one directory upcd ../../
move up 2 directories - 2 dots for one level upmv [~/filepathfrom ~/filepathto]
move file from one directory to anothermv [~/*.file-extension ~/filepathto]
move all files with the file extension (eg: .doc/.jpg) from one directory to anotheropen [file_name]
chsh -s
change shell to Zish, Bash or shchsh -s /bin/zsh
chsh -s /bin/sh
chsh -s /bin/bash
echo $SHELL
- which shell are you onzsh --emulate sh
- zsh can be made to emulate sh by executing the commandman -ls
manual for the ls command/
searchn
next matchb
move up a pagespacebar
move down a pageq
quitwqa
quit allcmp
- comparecmp -b
- compare bytescp
copy files or folderscp -i
date
date -r <filename>
date +%d
gives you the day of the date eg: 30df
how much of your disc is freedf -i
how much of you disc is free/used - infodf -h
- in a table how much of disc free
Read
cat <file_name>
outputs the contents of the file (good for small files)open <file_name>
opens the contents of the file (good for large files )less
(browse screen by screen)/
searchn
next matchb
move up a pagespacebar
move down a pageq
quittree
- folder structure graphic equivalent ofdu
Checking
<package_name> -v
list version/ sometimes<packagename> --version
whoami
- check who the user isps
- processesps -l
- process long version
Delete Destructive
rm <file_name>
remove file - destructive you won’t get the file back againrm -rf <file_name>
remove file force remove recursively - NO RECYCLE BIN IMPOSS TO RECOVER USE ADVISEDLYrmdir -p
remove directory and path - will remove only when emptyrmdir <dir>
removes directory if empty
`sudo or Super user rights
sudo
is the short version of super-user-do and is usually used to install packages - you will find many examples in the Installfest section
sudo
gives you super admin rights to your computer - if you are working with a team these rights may be reserved only to senior developers.- ` sudo chown` - change file owner or user
- ` sudo chown -r` change file owner or user recursively
- ` sudo chmod` change mode - changes user rights
Credit for content in this section - A premium Plural Sight course on shells
Change user rights
chmod
change modechmod u+x <file_name>
change mode to the user of the computer only can execute commands on the filechmod a+x <file_name>
change mode to any user
What is C-URL
C-URL also written as c-url, c-URL and curl, is an acryonm for client-URL (unique resource locator).
Your local device, when it needs to connect to a client (on a remote server or cloud-based platform) can use a curl command in the terminal. The data from the client’s remote server then can be safely transferred to your local device via an URL.
A curl is encoded and therefore different from a general URL where you can access web or mobile pages and data. The code is then decoded at your local device making the data from software development kits (SDKs) available for developers to use.
Search with grep
grep
search eg:grep <searchkeywords>*
this will search through text and filesgrep <searchkeywords> | sort
sorts the search out in alphabetical ordergrep <searchkeywords> | wc -l
search and list number of lines and word countgrep <searchkeywords>*
- search all matches - if key word is NodeJS matches and returns files
REFERENCES
Further reading