Hello there!! Knowing bash can make your life real easier, so why not trying it with me? I am a Mac user (do not feel ready for the Linux battles just yet!) so, everything I share here will work on Mac for sure, for other operating systems, it might need slight adjustments.
First of all, I will share the core commands followed by the cool short-cuts! and then starting from “File Organization”, we will work on using Bash together with simple simple examples:
To go to your terminal:
Press cmd and space, type terminal, and hit enter!
Now, let us start our exploration with the core commands!
To understand where you are working right now, type: “pwd”
Pwd stands for present working directory
To list what you have in that directory: ls
To have a more detailed list with additional information (including dates, user etc.): ls -l
To see the hidden files in that directory: ls -a
To change your directory: type “cd” (change directory)
If you want to go back to your home directory (from wherever you are): cd ~ or cd (both works fine).
Let us assume that you want to open up a file named Hello.pdf from your desktop (current directory).
You just need to type: open Hello.pdf
To open a directory: open . (The space between open and the dot is important, it does not work unless there is that space).
If you want to see your active processes:
If you want to quit, type: q
To clear your terminal screen, just type: clear
Now that you know the core commands, it is high time to learn the short-cuts!
Cmd + L: Deletes the last line
Ctrl +L or Cmd + K : Clear the screen
Ctrl + A: To go to the beginning of the line that you are currently typing
Ctrl + E: To go to the end of the line that you are currently typing
Ctrl + U: Clear the line before your cursor
Ctrl + K: Clear the line after your cursor
Ctrl + W: Delete the word before your cursor
Ctrl + T: Swap the last two characters of the word before your cursor
Escp + T: Swap the last two words before your cursor
If you want to create file: touch [filename]
Let us try this one together, make sure that you work on your Desktop (to be able to see what you are doing easily) by changing your directory to your desktop, and create a .docx file named hello:
cd ~/Desktop touch hello.docx
To rename your file as hello_new:
mv hello.docx hello_new.docx
You can remove that file:
To remove the file with confirmation (asking if you would like to delete or not):
rm -i hello_new.docx
Now, let us create a directory (folder) named Hello
To rename a directory (folder) from Hello to Hello_plus:
mv ~/Desktop/Hello ~/Desktop/Hello_plus
Now, let us create a file (Hello.docx) and move it to our new directory (Hello_plus):
touch Hello.docx mv ~/Desktop/Hello.docx ~/Desktop/Hello_plus/Hello.docx
Now, let us remove that directory:
rm -r Hello_plus
We used rm -r command for removing that directory because our directory had a content (word file). If it was an empty directory, to remove it:
Now, let us create a nested directory. First, we will create a directory named Hello, and inside that directory, let us create another directory named World.
mkdir -p Hello/World
To remove that nested directory:
rmdir -p Hello/World
If you want to copy your file (hello.docx) to a directory (Hello):
cp hello.docx Hello
To copy the directory (folder), now let us copy the Hello directory and name it as Hello_2:
cp -R ~/Desktop/Hello ~/Desktop/Hello_2
Let me know how your trial went!