Archive for category General Unix
Remove files with odd name
Posted by Lincoln Zuljewic Silva in General Unix on November 30, 2011
Sometimes an user create a file or directory with a odd filename, for example:
server@root:/root # touch /tmp/test/^Easasasasa.txt
This “^E” is the result of a CTRL+E. With “ls”, we have the following:
server@root:/tmp/test # ls -ltr
total 0
-rw-r----- 1 root sys 0 Nov 30 15:34 asasasasa.txt
Note that you cannot see the ^E in filename, so the system will not recognize it as “asasasasa.txt”:
server@root:/tmp/test # rm asasasasa.txt
rm: asasasasa.txt non-existent
The solution is work with the file’s inode:
server@root:/tmp/test # ls -lia
total 96
11 -rw-r----- 1 root sys 0 Nov 30 15:34 asasasasa.txt
5 drwxr-x--- 2 root sys 96 Nov 30 15:34 .
2 drwxrwxrwt 8 root root 49152 Nov 30 15:33 ..
The number “11” is the inode of the odd file. Now we can remove it using the find command:
server@root:/tmp/test # find . -inum 11
./asasasasa.txt
server@root:/tmp/test # find . -inum 11 -exec rm -rf {} \;
Create *.db files for sendmail
Posted by Lincoln Zuljewic Silva in General Unix on January 20, 2011
You can use the following command to create a *.db file to be used, for example, in sendmail:
makemap btree /etc/userdb.db < /etc/userdb
It will create a userdb.db based in the userdb file
Convert a text to/from UPPER to/from lower
Posted by Lincoln Zuljewic Silva in General Unix on November 5, 2010
You can use the following command do convert a file content from upper case do lower case:
cat /tmp/upper_file.txt |tr '[:upper:]' '[:lower:]' > /tmp/lower_file.txt
Or the following command to convert from lower to upper case:
cat /tmp/lower_file.txt |tr '[:lower:]' '[:upper:]' > /tmp/upper_file.txt
How to remove/move/copy/rename file that has a non-printable name
Posted by Lincoln Zuljewic Silva in General Unix on September 23, 2010
How to remove/move/copy/rename file that has a non-printable name, for example:
backup@root:/home/userhome/test # ls -la
total 2
-rw-rw-rw- 1 root sys 0 Sep 23 15:48
drwxrwxrwx 2 root sys 96 Sep 23 15:50 .
drwxr-xr-x 5 userhome adm 1024 Sep 23 16:20 ..
-rw-rw-rw- 1 root sys 0 Sep 23 15:47 -test
The easiest one is the file named "-test", you can do a "mv -- -test xx" to rename it to test, getting rid of the "-".
The most annoying is the other file, which apparently has the name "blank", but not quite.
There are two ways to find the real file name.,"ls -lq" e "ls -lb":
backup@root:/home/userhome/test # ls -lq
total 0
-rw-rw-rw- 1 root sys 0 Sep 23 15:48 ?
-rw-rw-rw- 1 root sys 0 Sep 23 15:47 xx
backup@root:/home/userhome/test # ls -lb
total 0
-rw-rw-rw- 1 root sys 0 Sep 23 15:48 \002
-rw-rw-rw- 1 root sys 0 Sep 23 15:47 xx
backup@root:/home/userhome/test # ls -li
total 0
17334 -rw-rw-rw- 1 root sys 0 Sep 23 15:48
17332 -rw-rw-rw- 1 root sys 0 Sep 23 15:47 xx
The "ls -lb" shows the non-printable characters with "\ XXX" where XXX is the ASCII representation of the non-printable character.
The "ls -lq" shows the non-printable characters with "???" (quantity of ? is defined by the amount of non-printable caracters).
The "ls -li" shows the file inode.
To handle this file, the best option is to use the "find".
- Using the find based on the inode:
find . -inum 17334 -exec mv {} asd \;
- Using find with "wildcards" (based on the ls-lq returned):
find . -type f -name "?" -exec mv {} asd \;
Be careful when using the find with "meta character"! If a file whose name has only one character, it will enter the result.