Navigating Around Bash
The directories in Ubuntu are in the following order:
By default when you open Ubuntu, you'll land on /home/<username>which in my case is /home/saatweek
pwd
cd ..
Remember, / means you're in the root directory |
ls
ls -a
Notice the additional . and .. files that were not shown earlier |
ls -l
ls -al
ls -la
Notice that the previously hidden directories ( . and .. ) are also included this time |
cd home
So here, I changed the directory to home and typed pwd to confirm that we are, indeed in the home directory |
ls
cd saatweek
See the example below
simply use mkdir followed by whatever name you want to give the directory
for example, type
mkdir sample_folder
A new folder got created after typing the command |
To create multiple new folders, simply type in multiple names divided by a space
For example, if I have to create sample_folder1, sample_folder2 and sample_folder3, then I'll write
mkdir sample_folder1 sample_folder2 sample_folder3
And now that we have seen how to make new directories, let's see how to delete them as well!
To delete an empty directory, type rmdir followed by the directory name. So if I have to delete sample_folder2, I'll write
rmdir sample_folder2
But remember, rmdir can only be used to delete empty directories.
Directories with any sort of content in them will prompt an error message
If you want to delete all the empty folders, type (this is usually used to get rid of the clutter)
rmdir *
That's basically it.
All that's left for us, is to cover one special case.
What if the file names have Spaces in between them?
Let's check out all the directories I have in my current path
Now if I try to get in 'My Folder' directory, it gives me this error:
To avoid this error, type in \ before the spaces, this will tell the system to avoid the space following the \
So your command will be
cd My\ Folder
Same rule goes for creating Directories with spaces in between their letters
For Example, type
mkdir My\ Folder2
If you were to write mkdir My Folder2 (without the \), then this would've created 2 different folders My and Folder2
End of the tutorial!
Now that we know how to navigate through directories and make and remove directories, let's clear up all the clutter that we've made so far, i.e., let's just delete all those empty files (guess the command?)
Notice how 3 folders couldn't be deleted, it's because they have files in them |
Bonus Shortcut if you made it this far!
You don't always have to type in the entire file name all the time, simply press TAB after writing first few words and the system will autocomplete the rest
If there are multiple files starting with the same few words that you just types, then pressing TAB twice will give you a list of all the files that start with those words
THE END
Don't forget to practice all the codes in your PC
Happy Coding!
Previous Post : Setting up Ubuntu and GCC
Next Post :
Comments
Post a Comment