Some Linux and Unix tips
Archive - Originally posted on "The Horse's Mouth" - 2008-11-18 18:25:10 - Graham EllisHow to make a woman equal to a man
[trainee@easterton ~]$ man ls
[trainee@easterton ~]$ woman ls
-bash: woman: command not found
[trainee@easterton ~]$ alias woman=man
[trainee@easterton ~]$ woman ls
[trainee@easterton ~]$
In Linux and Unix, the man command gives you a manual page ... but there is no woman command. If you want to be politically correct, you can use alias to make woman equal to man
How big are my files v how big are my directories
[trainee@easterton jimbo]$ du -sk *
64244 httpd-2.0.63
5776 httpd-2.0.63.tar.gz
8 MyJava.class
8 MyJava.java
8 newfile
8 RevTempconv.java
15268 tomcat-connectors-1.2.26-src
1420 tomcat-connectors-1.2.26-src.tar.gz
[trainee@easterton jimbo]$ ls -l
total 7244
drwxr-xr-x 12 jimbo apache 4096 Apr 24 2008 httpd-2.0.63
-rw-r--r-- 1 root root 5896358 Apr 24 2008 httpd-2.0.63.tar.gz
-rw-r--r-- 1 jimbo apache 430 Apr 24 2008 MyJava.class
-rw-r--r-- 1 jimbo apache 115 Apr 24 2008 MyJava.java
-rw-r--r-- 1 jimbo apache 6 Apr 23 2008 newfile
-rw-r--r-- 1 root root 1557 Apr 24 2008 RevTempconv.java
drwxr-xr-x 9 jimbo apache 4096 Dec 21 2007 tomcat-connectors-1.2.26-src
-rw-r--r-- 1 root root 1442605 Apr 25 2008 tomcat-connectors-1.2.26-src.tar.gz
[trainee@easterton jimbo]$
The ls command reports on the size of each symbol in a directory, whereas the du reports on the size of each symbol and what it contains. This means that you should use du if you want to see how much a director contains, but ls if you're just interested in the size of the directory's header records!
Moving files and directories with multiple owners
[root@easterton ~]# cd /home
[root@easterton home]# mkdir ../gosh
[root@easterton home]# tar cf - | (cd ../gosh; tar xpf -)
[root@easterton home]# tar cf - cloudy dave gordon| (cd ../gosh; tar xpf -)
[root@easterton home]# ls -l ../gosh
total 32
drwxr-xr-x 2 cloudy apache 4096 Nov 6 18:09 cloudy
drwxr-xr-x 4 dave dave 4096 Jun 24 10:07 dave
drwxr-xr-x 3 gordon apache 4096 Nov 18 14:02 gordon
[root@easterton home]#
If you're moving a part of your file system around on a Unix or Linux system, you might be inclined to use cp -r and indeed that will work well if you want the ownership of the copy transferred to the user making the copy. But if you want to copy a part of the file tree and preserver ownership, you must to so as root, and use the tar command. In the example above, we have output from tar so stdout, then piped into another tar in another directory, unpacking with the -p option to preserve ownership.
These examples ... from our Linux Basics and Linux Admin courses - run yesterday and today, and next running early next month ...
[trainee@easterton ~]$