In this post I will be listing all the Linux Tips & Tricks I come across in my journey to learn Linux.
This will be done on an Ubuntu 17.10 desktop installation, as I encounter each issue I will upload it here, mainly for my reference but also hopefully this can help someone else as well.
Delete non empty directory Linux
To delete a file in Linux you use the command rm <filename> linux will delete this file without question. To delete a a folder in Linux you use the command rmdir however you might get the following error. (Trying to delete a folder called test)
rm: cannot remove ‘test’: Is a directory
To remove a directory that contains other files or directories, use the following command.
rm -r test
In the example above, “test” is my folder I want to delete, you need to replace this with the name of the directory you want to delete. For example, if the directory was named “photos”, you would type rm -r photos at the prompt.
Executing the above command would delete all files and directories within the directory named in the command. However, it would also present a prompt for approval to delete each of the files. If you don’t want to receive a prompt for each file, use the following command instead.
rm -rf test
In the example above, the “test” directory, along with all files and directories within that directory, would be deleted with no prompt or message.
List contents of a folder with owner and permissions
If you want to see the contents of a folder you simply issue the command ls
[email protected]:/etc/ansible$ ls ansible.cfg backup.yml hosts switch.yml templates vxlan_spine.ios
However if you want to see more details about each file, like it’s permissions and owner then you need to use ls -l
[email protected]:/etc/ansible$ ls -l total 40 -rw-r--r-- 1 root root 18066 Jun 1 2017 ansible.cfg -rw-r--r-- 1 roger roger 704 Mar 27 13:17 backup.yml -rw-r--r-- 1 root root 126 Mar 24 09:04 hosts -rw-r--r-- 1 root root 120 Mar 24 09:08 switch.yml drwxr-xr-x 3 root root 4096 Mar 26 00:51 templates -rw-r--r-- 1 roger roger 39 Mar 26 10:56 vxlan_spine.ios
For even more detail of the folder, showing all files use ll
[email protected]:/etc/ansible$ ll
drwxrwxrwx 4 root root 4096 Mar 27 13:17 ./
drwxr-xr-x 125 root root 12288 Mar 27 06:54 ../
-rw-r–r– 1 root root 18066 Jun 1 2017 ansible.cfg
-rw-r–r– 1 roger roger 704 Mar 27 13:17 backup.yml
drwxr-xr-x 8 roger roger 4096 Mar 27 13:19 .git/
-rw-r–r– 1 root root 126 Mar 24 09:04 hosts
-rw-r–r– 1 root root 120 Mar 24 09:08 switch.yml
drwxr-xr-x 3 root root 4096 Mar 26 00:51 templates/
-rw-r–r– 1 roger roger 39 Mar 26 10:56 vxlan_spine.ios
Here you can see a hidden folder .git which was not visible before
This command ll is sometimes (and it varies on which distro you are running) aliased to different commands
In my case running Ubuntu, ll is aliased to ls -alF
To see this issue the following command
[email protected]:/etc/ansible$ type ll ll is aliased to `ls -alF'
This is the actual command which is being run when you type ll