• Increase font size
  • Default font size
  • Decrease font size
linux

Linux / Unix Command: gzip


usage: gzip [-cdfhlLnNrtvV19] [-S suffix] [file ...]
 -c --stdout      write on standard output, keep original files unchanged
 -d --decompress  decompress
 -f --force       force overwrite of output file and compress links
 -h --help        give this help
 -l --list        list compressed file contents
 -L --license     display software license
 -n --no-name     do not save or restore the original name and time stamp
 -N --name        save or restore the original name and time stamp
 -q --quiet       suppress all warnings
 -r --recursive   operate recursively on directories
 -S .suf  --suffix .suf     use suffix .suf on compressed files
 -t --test        test compressed file integrity
 -v --verbose     verbose mode
 -V --version     display version number
 -1 --fast        compress faster
 -9 --best        compress better
    --rsyncable   Make rsync-friendly archive
 file...          files to (de)compress. If none given, use standard input.


Examples

Compress:

gzip file.txt

In the above example command this would compress the file.txt file as file.txt.gz in the current directory.

Expand:

gunzip  file.txt.gz

In the above example command it would extract the file.txt from file.txt.gz.

 
Linux / Unix Command: chmod
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
  or:  chmod [OPTION]... OCTAL-MODE FILE...
  or:  chmod [OPTION]... --reference=RFILE FILE...
Change the mode of each FILE to MODE.
 
  -c, --changes           like verbose but report only when a change is made
      --no-preserve-root  do not treat `/' specially (the default)
      --preserve-root     fail to operate recursively on `/'
  -f, --silent, --quiet   suppress most error messages
  -v, --verbose           output a diagnostic for every file processed
      --reference=RFILE   use RFILE's mode instead of MODE values
  -R, --recursive         change files and directories recursively
      --help     display this help and exit
      --version  output version information and exit
 
Each MODE is one or more of the letters ugoa, one of the symbols +-= and
one or more of the letters rwxXstugo.
 

A bit mask created by ORing together zero or more of the following:

Octal Mode Number Description
0400 Allows the owner to read
0200 Allows the owner to write
0100 Allows the owner to execute files and search in the directory
0040 Allows group members to read
0020 Allows group members to write
0010 Allows group members to execute files and search in the directory
0004 Allows everyone or the world to read
0002 Allows everyone or the world to write
0001 Allows everyone or the world to execute files and search in the directory
1000 Sets the sticky bit
2000 Sets the setgid bit
4000 Sets the setuid bit

First digit in the above mode number is used to set setuid, setgid, or sticky bit. Each remain
digit set permission for the owner, group, and world as follows:

  1. 4 = r (Read)
  2. 2 = w (Write)
  3. 1 = x (eXecute)

So you end up creating the triplets for your user by adding above digits. For e.g.

  • To represent rwx triplet use 4+2+1=7
  • To represent rw- triplet use 4+2+0=6
  • To represent r-- triplet use 4+0+0=4
  • To represent r-x triplet use 4+0+1=1

To only give full permission to user, use it as follows:
chmod 0700 file.txt

  • 0 - Use set setuid, setgid, or sticky bit
  • 7 - Full permission for owner (rwx = 4+2+1=7)
  • 0 - Remove group permission (--- = 0+0+0=0)
  • 0 - Remove world permission (--- = 0+0+0=0)
 
 
- rw rw- r-- 1 hope 123 Feb 03 15:36 file.txt
File owner group everyone else links owner size mod date file name

 

 

 

 The following table describes some of the standard directories on Linux systems.

DIRECTORY DESCRIPTION
/ The ancestor of all directories on the system; all other directories are subdirectories of this directory, either directly or through other subdirectories.
/bin Essential tools and other programs (or binaries).
/dev Files representing the system's various hardware devices. For example, you use the file `/dev/cdrom' to access the CD-ROM drive.
/etc Miscellaneous system configuration files, startup files, etcetera.
/home The home directories for all of the system's users.
/lib Essential system library files used by tools in `/bin'.
/proc Files that give information about current system processes.
/root The superuser's home directory, whose username is root. (In the past, the home directory for the superuser was simply `/'; later, `/root' was adopted for this purpose to reduce clutter in `/'.)
/sbin Essential system administrator tools, or system binaries.
/tmp Temporary files.
/usr Subdirectories with files related to user tools and applications.
/usr/X11R6 Files relating to the X Window System, including those programs (in `/usr/X11R6/bin') that run only under X.
/usr/bin Tools and applications for users.
/usr/dict Dictionaries and word lists (slowly being outmoded by `/usr/share/dict').
/usr/doc Miscellaneous system documentation.
/usr/games Games and amusements.
/usr/info Files for the GNU Info hypertext system.
/usr/lib Libraries used by tools in `/usr/bin'.
/usr/local Local files -- files unique to the individual system -- including local documentation (in `/usr/local/doc') and programs (in `/usr/local/bin').
/usr/man The online manuals, which are read with the man command (see Reading a Page from the System Manual).
/usr/share Data for installed applications that is architecture-independent and can be shared between systems. A number of subdirectories with equivalents in `/usr' also appear here, including `/usr/share/doc'`/usr/share/info', and `/usr/share/icons'.
/usr/src Program source code for software compiled on the system.
/usr/tmp Another directory for temporary files.
/var Variable data files, such as spool queues and log files.

 

 You have to restart the NTP process every time you make a change to the configuration file for the changes to take effect on the running process.

To get NTP configured to start at boot, use the line:

[root@bigboy tmp]# chkconfig ntpd on

To start, stop and restart NTP after booting, follow these examples:

[root@bigboy tmp]# service ntpd start
[root@bigboy tmp]# service ntpd stop
[root@bigboy tmp]# service ntpd restart

Testing And Troubleshooting NTP

After configuring and starting NTP, you should test it to make sure it is working. Here are some guidelines you can follow to get NTP working correctly.

 

 

 

 [root@localhost sysconfig]# more iptables

# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
 
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -s 200.103.200.65/28 --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -s 220.200.100.1/32 --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -s 220.200.100.1/32 --dport 80 -j ACCEPT
 
-A RH-Firewall-1-INPUT -s 0.0.0.0/0.0.0.0 -j DROP
 
COMMIT
 

 Checking your Linux Kernel Version: Once your up and running with your favorite Linux distribution, you might find the need to install additional software packages or drivers. Some of these software applications or drivers can be specific to a Linux Kernel version in which case you will need to find this information. Finding the Kernel Version, Release information and Operating System from a running system is fairly straight forward and can be done directly from a terminal.

 
Locating your Linux Kernel Version:
 
Open up a terminal and type one of the following commands listed in bold text.
 
uname -a  (prints all information)
 
uname -r  (prints the kernel release)
 
uname -v  (prints the kernel version)
 
uname -o  (prints the operating system)
 
 

 1. Plan the layout of the filesystem with the new drive 

2. Partition the new hard drive 
3. Format the new partitions 
4. Test the new space 
5. Copy data from old to new partition (optional) 
6. Edit /etc/fstab 
7. Reboot 
8. Remove old data (optional)

Here is the details about each one.

1. Plan the new filesystem. Where would you like to use the new space? Do

df

to print a summary of free/used space on each of the existing mounted partitions. Do

du

on selected directories to find their size.

For example, I would consider using new hard drive space in one of the following mount points:

/usr/local 
/home 
/home/share/downloads 
/usr/local/mp3s 
/usr/local/dos_data

Here is Details.

/usr/local is suposed to survive any upgrade of Linux. It is nice to have it on a separate partition because I can even reformat other partitions without affecting my local contents stored in /usr/local. I surely want it of the type "ext2" or perhaps "reiserfs".

/home contains user data. Surely, it is the data that deserves the most care. It is obviously supposed to survive any upgrade of Linux. Wow, obviously I want it on a separate partition. The type is normally "ext2" or "raiserfs".

/usr/local/mp3s is a non-standard Linux directory. I may keep my MP3 (music) files there. Those tend to be large.

/usr/local/dos_data. Another non-standard directory. If I dual boot, I would consider making an extra partion of the type "DOS FAT32" or similar so as to share files between MS Windows and Linux transparently (both ways). I would configure all the Windows-based programs to use this "drive" as the default location for all user-generated files. I could even have "mp3s", "cds" and other such directories in this location. The serious drawback of this approach--MS Windows may insist on messing up with this partion on re-install.

2. Partition the new hard drive. For example, if my new harddrive is the slave on the second IDE interface (perhaps the "fourth" IDE drive), I could use:

cfdisk /dev/hdd

or the more old-fashioned (and standard) tool:

fdisk /dev/hdd

If your drive is not "hdd" adjust the above command as needed.

hda -- first ide master (whole disk) 
hdb -- first ide slave 
hdc -- second ide master 
hdd -- second ide slave 
sda -- first scsi (whole disk) 
sdb -- second scsi (whole disk) 
... 
sdp -- sixteenth scsi (whole disk)

For other disks, consult /usr/src/Linux/Documentation/devices.txt.

Most of the time,  Linux partitions to be of the type ext2 ("Linux").

Partitioning can be tricky--if you never have done it, read man fdisk and man cfdisk. It is very easy to delete a partition with all your data. Make sure you know which disk you are working with!

fdisk or cfdisk does not make any changes to the hard drive until I write the new partition layout. So if I make a bad mistake, I can always quit without writing. I write the layout to the drive only when I am completely done.

3. Format each partition. For example, to format the first partition, while checking for bad blocks (-c), I would do:

mkfs -c -t ext2 /dev/hdd1

4. Test the new partitions around. Mount the new partitions manually (the mount directory must exist and be empty). Copy a bunch of files to each partition. View/edit a couple of random files. Delete them all.

5. Copy data. Optional--only if you would like to move data from an old partition to a new partition. Go to the single-user mode (init 1). Mount the new partition manually. Copy the data from the old partition to the new partition. Careful with the old data, you probably don't want to lose it if you made a mistake, so I wouldn't delete it yet--I rename the top level directory appropriately. E.g.,

cp -R /usr/local/ /mnt/hdd1/ 
mv /usr/local/ /usr/local.old.backup_of_2005-04-21

6. Edit the file /etc/fstab. Modify it to reflect your new filesystem layout. Perhaps, insert the mountpoint for the new partition(s) or modify any old mountpoints as needed. For example, if moving /usr/local to its own partition, I would need to add to add a line like this:

/dev/hdd1 /usr/local ext2 defaults 1 2

7. Reboot and test. The alternative to reboot is to unmount old and mount new mount points. For example:

umount /usr/local 
mount -a

but hard reboot may be a more rigorous test of the new layout.

8. Remove old data. After a few days, when I have the confidence everything is really working fine

From:http://www.debianhelp.co.uk/newharddisk.htm

 

Display list of all open ports on linux 

[root@hc168 ~]# netstat -tulpn

output

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      27158/mysqld        
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      2463/vsftpd         
tcp        0      0 :::12655                    :::*                        LISTEN      2418/sshd           
tcp        0      0 :::80                       :::*                        LISTEN      3384/httpd          
tcp        0      0 :::8181                     :::*                        LISTEN      3384/httpd
 

 Most of the hardware information can be extracted from /proc file system, for example display CPU and Memory information, enter:
cat /proc/meminfo
cat /proc/cpuinfo

 

[root@HCMRTG_BY_YaoBin ~]# cat /proc/meminfo

MemTotal:      3500784 kB

MemFree:        127428 kB

Buffers:         68472 kB

Cached:        3065788 kB

SwapCached:          0 kB

Active:         762384 kB

Inactive:      2547700 kB

HighTotal:     2621232 kB

HighFree:         5368 kB

LowTotal:       879552 kB

LowFree:        122060 kB

SwapTotal:      779112 kB

SwapFree:       779032 kB

Dirty:           30616 kB

Writeback:         372 kB

AnonPages:      175812 kB

Mapped:          17244 kB

Slab:            52968 kB

PageTables:       2212 kB

NFS_Unstable:        0 kB

Bounce:              0 kB

CommitLimit:   2529504 kB

Committed_AS:   419104 kB

VmallocTotal:   114680 kB

VmallocUsed:      2552 kB

VmallocChunk:   111944 kB

HugePages_Total:     0

HugePages_Free:      0

HugePages_Rsvd:      0

Hugepagesize:     4096 kB

 

[root@HCMRTG_BY_YaoBin ~]# cat /proc/cpuinfo

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 15

model           : 4

model name      : Intel(R) Xeon(TM) CPU 3.00GHz

stepping        : 10

cpu MHz         : 3000.370

cache size      : 2048 KB

physical id     : 0

siblings        : 2

core id         : 0

cpu cores       : 1

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 5

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid cx16 xtpr lahf_lm

bogomips        : 6003.78

 

processor       : 1

vendor_id       : GenuineIntel

cpu family      : 15

model           : 4

model name      : Intel(R) Xeon(TM) CPU 3.00GHz

stepping        : 10

cpu MHz         : 3000.370

cache size      : 2048 KB

physical id     : 0

siblings        : 2

core id         : 0

cpu cores       : 1

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 5

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid cx16 xtpr lahf_lm

bogomips        : 5999.40

 

processor       : 2

vendor_id       : GenuineIntel

cpu family      : 15

model           : 4

model name      : Intel(R) Xeon(TM) CPU 3.00GHz

stepping        : 10

cpu MHz         : 3000.370

cache size      : 2048 KB

physical id     : 3

siblings        : 2

core id         : 0

cpu cores       : 1

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 5

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid cx16 xtpr lahf_lm

bogomips        : 5999.43

 

processor       : 3

vendor_id       : GenuineIntel

cpu family      : 15

model           : 4

model name      : Intel(R) Xeon(TM) CPU 3.00GHz

stepping        : 10

cpu MHz         : 3000.370

cache size      : 2048 KB

physical id     : 3

siblings        : 2

core id         : 0

cpu cores       : 1

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 5

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe lm constant_tsc pni monitor ds_cpl cid cx16 xtpr lahf_lm

bogomips        : 5999.47

 

 

 

 uname -a should give you all the information you want

uname -l

 
[root@HCMRTG_BY cron]# uname -a
Linux HCMRTG_BY_YaoBin 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:12 EDT 2008 i686 i686 i386 GNU/Linux