Sunday, January 5, 2014

How to delete a file with a dash in front of it.

There are times when you accidentally create a file with a dash in front of it. And removing it with 'rm' command can be difficult. But there are quite a few ways to delete it.

1) Delete the file using the full path:

Let's say there is a file called -roger.txt and we want to delete it. Using 'rm' command could have a disastrous effect because the file name starts with '-r'. One way to delete is using a full path.

root@myhost:~/test# ls -l
total 0
-rw-r--r-- 1 root root 0 Jul 27 20:43 -roger.txt
root@myhost:~/test#

root@myhost:~/test# rm /home/myhost/test/-roger.txt
root@batput:~/test#

2) Delete using relative path:

This one is similar to the first one. 

root@myhost:~/test# rm ./-roger.txt
root@myhost:~/test#

3) Using the special flag '--' (double dash):

The man page of rm command provides a wonderful way to delete a file with a dash in front of it. By using double flag called -- (double dash/hyphen). 

root@myhost:~/test# rm -- -roger.txt
root@myhost:~/test#

For more information read the man page of rm command.


How to quickly find the largest files on the system.

You can execute the du command shown below to find the largest files on the system.

bash# du -ch -x --max-depth=1



--

Recursively checking the permissions of a file/directory tree using - namei command

There are situations when you want to troubleshoot the permissions issue on a file buried under multiple directory levels. You would want a simple mechanism to check the permissions of the file in question and all of its parent directories as well. Well -- namei -- does just that. 


bash# namei -l /var/tmp/dir1/dir2/file
f: /var/tmp/dir1/dir2/file
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxrwxrwt root root tmp
drwxr-xr-x root root dir1
drwxr-xr-x root root dir2
-rw-r--r-- root root file



-l stands for long listing.


--

How to fix broken rpm packages

 Run the following command:


bash# rpm -e --nodeps --justdb <packagename>


--