Linux/Unix changing shell prompt

\u – Username
\h – Hostname
\w – Full path of the current working directory


$ pwd
/var/tmp


$ export PS1="# "
#

hostname pats
export PS1="\h# "
pats#

pats# export PS1="\u@\h $ "
dennis@pats $


dennis@pats $  export PS1="\u@\h \w# "
dennis@pats ~#  cd /tmp
dennis@pats /tmp#




Unix/Linux: Changing the date of a file


SYNTAX:  touch -t [[CC]YY]MMDDhhmm[.ss] file

# ls -l myfile.txt
-rw-r--r-- 1 root root 3735707 Feb  8 05:56 myfile.txt

# stat myfile.txt
  File: `myfile.txt'
  Size: 3735707       Blocks: 7304       IO Block: 4096   regular file
Device: 801h/2049d    Inode: 13895185    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-02-08 05:56:14.977494275 -0500
Modify: 2013-02-08 05:56:23.572695178 -0500
Change: 2013-02-08 05:56:23.572695178 -0500
 Birth: -



Change the date to 12/25/1999 at 10:30 AM:

# touch -t 199912251030 myfile.txt

# ls -l myfile.txt
-rw-r--r-- 1 root root 3735707 Dec 25  1999 myfile.txt

# stat myfile.txt
  File: `myfile.txt'
  Size: 3735707       Blocks: 7304       IO Block: 4096   regular file
Device: 801h/2049d    Inode: 13895185    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 1999-12-25 10:30:00.000000000 -0500
Modify: 1999-12-25 10:30:00.000000000 -0500
Change: 2013-02-08 05:57:33.682176907 -0500
 Birth: -

UNIX/Linux: Split and Join Files

How to split a file into smaller chuncks:

# ls -l
total 93564
-rw-rw-r-- 1 dennis dennis 95805440 Feb  8 05:20 myfile.tar

# sum myfile.tar
17765 93560

# split -b 25M myfile.tar chunck

# ls -l
total 187124
-rw-r--r-- 1 dennis dennis   26214400 Feb  8 05:28 chunckaa
-rw-r--r-- 1 dennis dennis   26214400 Feb  8 05:28 chunckab
-rw-r--r-- 1 dennis dennis   26214400 Feb  8 05:28 chunckac
-rw-r--r-- 1 dennis dennis   17162240 Feb  8 05:28 chunckad
-rw-rw-r-- 1 dennis dennis 95805440 Feb  8 05:20 myfile.tar



Putting the pieces back together.

# cat chuncka* > another.tar

# ls -l
total 280688
-rw-r--r-- 1 dennis dennis   95805440 Feb  8 05:28 another.tar
-rw-r--r-- 1 dennis dennis   26214400 Feb  8 05:28 chunckaa
-rw-r--r-- 1 dennis dennis   26214400 Feb  8 05:28 chunckab
-rw-r--r-- 1 dennis dennis   26214400 Feb  8 05:28 chunckac
-rw-r--r-- 1 dennis dennis   17162240 Feb  8 05:28 chunckad
-rw-rw-r-- 1 dennis dennis 95805440 Feb  8 05:20 myfile.tar

# sum another.tar
17765 93560

Linux/Unix set CDPATH to define the base directory

$ pwd
/home/dennis


$ cd tmp
bash: cd: tmp: No such file or directory


$ export CDPATH=/var

$ cd tmp
/var/tmp

Linux/Unix diff command example

$ cat file1
Brian Jones  - The Rolling Stones
George Harrison - The Beatles
John Lennon - The Beatles
Keith Richards - The Rolling Stones
Mick Jagger - The Rolling Stones
Paul McCartney - The Beatles
Ringo Starr - The Beatles
Ron Wood - The Rolling Stones


$ cat file2
Brian Jones  - The Rolling Stones
George Harison - The Beatles
John Lennon - The Beatles
Keith Richards - The Rolling Stones
Mick Jagger - The Rolling Stones
Paul McCartney - The Beatles
Ringo Starr - The Baatles
Ron Wood - The Rolling Stones


$ diff file1 file2
2c2
< George Harrison - The Beatles
---
> George Harison - The Beatles
7c7
< Ringo Starr - The Beatles
---
> Ringo Starr - The Baatles



$ diff -y file1 file2 --w=75
Brian Jones  - The Rolling Stones    Brian Jones  - The Rolling Stones
George Harrison - The Beatles         |    George Harison - The Beatles
John Lennon - The Beatles        John Lennon - The Beatles
Keith Richards - The Rolling Stones    Keith Richards - The Rolling Stones
Mick Jagger - The Rolling Stones    Mick Jagger - The Rolling Stones
Paul McCartney - The Beatles        Paul McCartney - The Beatles
Ringo Starr - The Beatles         |    Ringo Starr - The Baatles
Ron Wood - The Rolling Stones        Ron Wood - The Rolling Stones


Linux/Unix paste example


$ cat letters
ubuntu
linux
suse
redhat
solaris

$ cat numbers
1111
2222
7777
3333
5555

$ paste numbers letters
1111    ubuntu
2222    linux
7777    suse
3333    redhat
5555    solaris

Display file or file system status using stat


$ stat -f /
  File: "/"
    ID: 8d5b55bda98460a Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 59315815   Free: 58075863   Available: 55062773
Inodes: Total: 15073280   Free: 14839112


$ stat bands
  File: `bands'
  Size: 267           Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d    Inode: 13764178    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  dennis)   Gid: ( 1000/  dennis)
Access: 2013-02-06 05:20:27.457632563 -0500
Modify: 2013-02-06 05:20:25.921777852 -0500
Change: 2013-02-06 05:20:25.965773691 -0500
 Birth: -