Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iqbalrony/2edc74548dd43a59ef290347af09f462 to your computer and use it in GitHub Desktop.
Save iqbalrony/2edc74548dd43a59ef290347af09f462 to your computer and use it in GitHub Desktop.
A list of most used terminal command list.
=======================================================================
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//////////////// Most Useful Terminal Command List \\\\\\\\\\\\\\\\
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
=======================================================================
01. Current Working Directory:
==============================
pwd
02. Clear the Window:
=====================
clear
03-1. Content List of Current Directory:
========================================
ls
03-2. Content List of Current Directory (Detailed list view):
=============================================================
ls -l
03-3. Content List of Current Directory (All files including hidden ones):
==========================================================================
ls -a
03-4. Content List of Current Directory (Detailed list view / All files including hidden ones):
==============================================================================================
ls -la
04. Change Directory:
=====================
cd
Forward: ./ OR / (Optional)
Backward: ../
Backward 3 step: ...
Backward 4 step: ....
Folder with space in the name:
"/Folder name with space/"
OR
Folder\ name\ with\ space
Different Drive: DRIVE_LETTER:
Example:
--------
cd nextFolder
cd /nextFolder
cd ./nextFolder
cd ../previousFolder
cd ...
cd ....
cd "./nextFolder/Folder name with space/"
cd ./nextFolder/Folder\ name\ with\ space/
cd D:
cd D:/nextFolder
05. Go to Home Directory:
=========================
cd ~
OR
~
06. Switch Between Last 2 Directories:
======================================
cd -
OR
-
07. Open Any Text File on Terminal (Read-Only):
===============================================
cat
Example:
--------
cat file.txt
cat file.doc
cat FolderName/README.md
08. Open Any File with Default Application:
===========================================
xdg-open
Example:
--------
xdg-open file.txt
xdg-open file.doc
xdg-open file.mp4
09. Open Any File with Code Editors:
====================================
editorName fileName
Example:
--------
Nane: nano file.txt
Vim: vim file.txt
Emacs: emacs file.txt
VS Code: code file.txt
10. Create New File:
====================
touch
Example:
--------
touch newFile.txt
touch index.html style.css app.js
11. Create New File and Add Texts at Once:
==========================================
cat > fileName
Note:
------
*** This command will create the file and give us option to add multiple line texts.
*** After done adding text, we need to press Cmd+D 2 times. 1st press will save the file and 2nd press will send us back to main Terminal.
Example:
--------
cat > index.html
12. Create New Folder:
======================
mkdir
Example:
--------
mkdir NewFolderName
mkdir "New Folder Name"
mkdir NewFolder1 NewFolder2 NewFolder3
13. Create New Folder and Enter to That at Once:
================================================
take
Example:
--------
take NewFolderName
take "New Folder Name"
14. Move/Rename Files/Folders:
==============================
mv
CAUTION:
--------
*** It will REPLACE any existing file/folder with same name from the target directory.
*** It's GOOD PRACTICE to use sub-command "-i" with it. so that it will asks for confirmation.
14-1. Move Single File/Folder:
==============================
mv existingFile targetPath
mv existingFolder targetPath
Example:
--------
mv file.txt Target/Directory -i
mv FolderName Target/Directory -i
mv FolderName/file.txt Target/Directory -i
14-2. Move Multiple Files/Folders:
==================================
mv existingFile1 existingFile2 existingFile3 targetPath
mv existingFolder1 existingFolder2 existingFolder3 targetPath
Example:
--------
mv file1.txt file2.txt file3.txt Target/Directory -i
mv Folder1 Folder2 Folder3 Target/Directory -i
mv Folder1/file1.ext Folder2/file2.ext Folder3/file3.ext Target/Directory -i
14-3. Rename File/Folder:
=========================
mv existingFileName newFileName
mv existingFolderName newFolderName
Example:
--------
mv existingName.txt newName.txt -i
mv existingFolderName newFolderName -i
14-4. Move + Rename File/Folder:
================================
mv existingFile targetPath/newName
mv existingFolder targetPath/newName
Example:
--------
mv existingName.txt targetPath/newName.txt -i
mv existingFolderName targetPath/newFolderName -i
15. Copy File/Folder:
=====================
cp
CAUTION:
--------
*** It will REPLACE any existing file/folder with same name from the target directory.
*** It's GOOD PRACTICE to use sub-command "-i" with it. so that it will asks for confirmation.
15-1. Copy Single File/Folder:
==============================
cp fileName targetPath
cp folderPath targetPath
Example:
--------
cp file.txt Target/Directory -i
cp FolderName Target/Directory -i
cp FolderName/file.txt Target/Directory -i
15-2. Copy Multiple Files/Folders:
==================================
cp file1 file2 file3 targetPath
cp Folder1 Folder2 Folder3 targetPath
Example:
--------
cp file1.txt file2.txt file3.txt Target/Directory -i
cp Folder1 Folder2 Folder3 Target/Directory -i
cp Folder1/file1.ext Folder2/file2.ext Folder3/file3.ext Target/Directory -i
15-3. Copy + Rename File/Folder:
================================
cp fileName targetPath/newName
cp FolderName targetPath/newName
Example:
--------
cp file.txt targetPath/newName.txt -i
cp FolderName targetPath/newFolderName -i
16. Delete File:
================
rm
CAUTION:
--------
*** DON'T use it unless you have NO alternative. It will REMOVE file/folder permanently.
*** It's GOOD PRACTICE to use sub-command "-i" with it. so that it will asks for confirmation.
*** To allow sending the removed file/folder into TRASH or RECYCLE BIN, please take a look at the "Useful Tips" at bottom of this page.
Example:
--------
rm fileName.txt -i
17. Delete Folder:
==================
rmdir
CAUTION:
--------
*** DON'T use it unless you have NO alternative. It will REMOVE file/folder permanently.
*** It's GOOD PRACTICE to use sub-command "-i" with it. so that it will asks for confirmation.
*** To allow sending the removed file/folder into TRASH or RECYCLE BIN, please take a look at the "Useful Tips" at bottom of this page.
Example:
--------
rmdir FolderName -i
rmdir "Folder Name" -i
18. Details about Any Terminal Command:
=======================================
man
Example:
--------
man ls
man cd
man rm
19. Details about Any Program:
==============================
programName --help
Example:
--------
git --help
code --help
node --help
20. Exit from the current terminal tab:
=======================================
exit
=====================
Useful Tips:
=====================
01. Auto fill up commands: Tab
-----------------------------
*** Pressing Tab after writting partial keyword/folder/file name auto fills the name. Or shows full list of names if there are more than one.
*** Pressing Tab multiple times shows full list of similar folders/files and allows navigate between them. Then it also allows navigate with arrow keys.
*** After writting a sub command "-" sign, pressing Tab suggests and allows to navigate all sub-commands under the current command keyword.
02. Recently typed command history: Arrow Up
-------------------------------------------
*** After pressing Arrow Up, it will allow navigate through multiple history using Arrow Up and Arrow Down
*** After writting partial command, pressing Arrow Up or Arrow Down will allow to navigate through related command history
*** Pressing Cmd+R allows to search through the recent command history.
03. Sending removed file/folder into "Trash" or "Recylce Bin: trash
------------------------------------------------------------------
*** Using "trash-cli" 3rd-party tool:
==> https://github.com/sindresorhus/trash-cli
04.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment