My CLI cheat sheet
This is my CLI cheat sheet of the commands I most frequently use
List
ls- list filesls - alist all including hidden filesls - llist long versionls - laorls -lahlist all including hidden files in long versionls - slist and sortls -ltlist 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 0list 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 \fileconcatinates files into one file - you will get a file withas the file name echoprints to consolenano create_reportfor nano editors
Copy
cp [~/filepathfrom ~/filepathto]copy file from one directory to anothercp [~/*.file-extension ~/filepathto]© 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
cdchange 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 -schange shell to Zish, Bash or shchsh -s /bin/zshchsh -s /bin/shchsh -s /bin/bashecho $SHELL- which shell are you onzsh --emulate sh- zsh can be made to emulate sh by executing the commandman -lsmanual for the ls command/searchnnext matchbmove up a pagespacebarmove down a pageqquitwqaquit allcmp- comparecmp -b- compare bytescpcopy files or folderscp -idatedate -r <filename>date +%dgives you the day of the date eg: 30dfhow much of your disc is freedf -ihow 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)/searchnnext matchbmove up a pagespacebarmove down a pageqquittree- folder structure graphic equivalent ofdu
Checking
<package_name> -vlist version/ sometimes<packagename> --versionwhoami- 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 -premove 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
sudogives 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
chmodchange 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
grepsearch eg:grep <searchkeywords>*this will search through text and filesgrep <searchkeywords> | sortsorts the search out in alphabetical ordergrep <searchkeywords> | wc -lsearch and list number of lines and word countgrep <searchkeywords>*- search all matches - if key word is NodeJS matches and returns files