GNU/Linux notes

From OriWiki

Jump to: navigation, search

image:Gnu_linux.png

Contents

realpath to current directory

readlink -f . 

or if realpath is installed

realpath . 

determining the path of which a script resides

The following seems to be problematic:

dirname $0  

if the script is run using a full path, everything works fine. relative path.. problematic .. source -- give the path of the shell interpreter (/bin/ or something..)

hierarchical copy of directory content

the following example shows that 'cp -r dir1/* dir2/' overwrites any files in the hierarchy but leaves existing files in a subdirectory untouched

[ori@sun2 tmp]$ mkdir dir1 
[ori@sun2 tmp]$ mkdir dir2 
[ori@sun2 tmp]$ mkdir dir1/dir
[ori@sun2 tmp]$ mkdir dir2/dir
[ori@sun2 tmp]$ echo "created in dir1" > dir1/dir/f1
[ori@sun2 tmp]$ echo "created in dir1" > dir1/dir/f2
[ori@sun2 tmp]$ echo "created in dir2" > dir2/dir/f1
[ori@sun2 tmp]$ echo "created in dir2" > dir2/dir/f3
[ori@sun2 tmp]$ cp -r dir1/* dir2/ 
[ori@sun2 tmp]$ cd dir2 
[ori@sun2 dir2]$ cd dir 
[ori@sun2 dir]$ ls
f1  f2	f3
[ori@sun2 dir]$ cat * 
created in dir1
created in dir1
created in dir2

create a new account

Login as root

useradd <username>

changing the new account's password:

passwd <username>

source and .

These two are the same:

source shellScript.sh 
. shellScript.sh 

And they mean that the shell script will run and effect the current shell (not in a new spawned child shell)

wc

recursive wc:

 wc -l `find . -name *.cpp`

copy cd

sudo umount /dev/cdrom
readcd dev=/dev/cdrom f=file.iso

on Gutsy Gibbon, the following seemed to work:

readcd dev=/dev/cdrom1 f=file.iso

ls sorted by modification time

ls -t 

Combined with the detailed view: ls -lt

which packages are installed on the system?

pkginfo
Personal tools