Unix Commands
From Null-pointer
Adding a user
As root user.
[root@localhost ~]# useradd -d /export/home/[username] [username]
[root@localhost ~]# chown [username] /export/home/[username]
[root@localhost ~]# passwd [username]
Groups
What group am I
[KaneP01@localhost root]# groups KaneP01
[root@localhost ~]# groups root bin daemon sys adm disk wheel
Add a group
[root@localhost ~]# groupadd newGroup[1]
Add a new user to a group
[root@localhost ~]# useradd -G group newUser[1]
Add a existing user to existing group
[root@localhost ~]# usermod -a -G ftp KaneP01
Set password to never expire
[root@localhost ~]# passwd -x -1 [username]
.profile
SHELL=/usr/bin/bash PS1=$'\\[\\033[1;30m\\][\\[\\033[1;37m\\]\\\\u\\[\\033[0;37m\\]@\\[\\033[1;37m\\]\\\\h\\ [\\033[1;30m\\]:\\[\\033[1;36m\\]\\W\\[\\033[1;30m\\]]\\[\\033[0;37m\\] ' alias ls='ls -F'
Advanced alias
# Default to human readable figures alias df='df -h' alias du='du -h'
alias ls='ls -hF --color=tty' # classify files in colour alias dir='ls --color=auto --format=vertical' alias ll='ls -l' # long list
Fixed IP Address
# cd /etc/sysconfig/network-scripts # less ifcfg-eth0
DEVICE=eth0 IPADDR=192.168.1.100 NETMASK=255.255.255.0 BOOTPROTO=static ONBOOT=yes # # The following settings are optional # BROADCAST=192.168.1.255 NETWORK=192.168.1.0
Getting the IP Address Using DHCP
# cd /etc/sysconfig/network-scripts # less ifcfg-eth0
DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes
Snoop
snoop -o network.snoop port 8080
Untar
[root@localhost ~]# tar xvzf file-1.0.tar.gz
[root@localhost ~]# tar xvjf file-1.0.tar.bz2
[root@localhost ~]# tar xvf file-1.0.tar
- x = eXtract, this indicated an extraction ( c = create to create )
- v = verbose (optional) the files with relative locations will be displayed.
- z = gzip-ped; j = bzip2-zipped
- f = from/to file ... (what is next after the f is the archive file)
Untar multiple files
[root@localhost ~]# for i in *.tar.gz; do tar -xvzf $i; done [2]
rpm
yum
finding out what package to download for a dependency
[root@localhost ~]# yum provides 'libXm.so.3'
output redirect
[root@localhost ~]# ls > outfile.txt 2>&1
also works in 4NT
find files
[root@localhost ~]# find . -name "ruby" -print
[root@localhost ~]# find . -name "*ruby*" -print
taken from http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm
count files in a folder
[root@localhost ~]# ls | wc -l [3] 939
Find files containing "string"
[root@localhost ~]# find . -type f | xargs grep string [4]
How much disk space is a folder taking
[root@localhost ~]# du -hcs 19G . 19G total
Set Date, Time, and Zone
[root@localhost ~]# date -s "11 MAR 2010 16:25"
[root@localhost ~]# ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
[root@localhost ~]# vi /etc/sysconfig/clock ZONE='Europe/London' UTC=false ARC=false
- http://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/
- http://www.wikihow.com/Change-the-Timezone-in-Linux
ntp
if using ntp
[root@localhost ~]# /sbin/service ntpd stop
Immediately reset the clock to the correct time
[root@localhost ~]# ntpd -g -q
[root@localhost ~]# /sbin/service ntpd start
services
start
[root@localhost ~]# svc -u /service/myservice
stop
[root@localhost ~]# svc -d /service/myservice
uptime
[root@localhost ~]# svstat -d /service/myservice
http_proxy
[root@localhost ~]# export http_proxy='http://www.proxy.com:80'
DISPLAY
[root@localhost ~]# export DISPLAY=my_machine_name:0.0'
killall
kill all processes[5]
kill all tomcats
[root@localhost ~]# killall java
beware that this will kill everything being run by java!.
error: cannot open Conflictname index using db3
With error:
error: cannot open Conflictname index using db3 - No such file or directory (2) error: can't create transaction lock on /var/lib/rpm/__db.000
Solve:
# rm -rf /var/lib/rpm/__db.* # rpm --rebuilddb
Version
[root@localhost ~]# [cognos@gl01265m ~]$ cat /proc/version Linux version 2.6.18-194.17.4.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Mon Oct 25 15:50:53 EDT 2010 [6]
[root@localhost ~]# [cognos@gl01265m ~]$ uname -a Linux gl01265m.gamesys.corp 2.6.18-194.17.4.el5 #1 SMP Mon Oct 25 15:50:53 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux [7]
Navigating
- CTRL-A = go to beginning of line
- CTRL-E = go to end of line
- CTRL-T = transpose two letters [8]
References
- ↑ 1.0 1.1 Vivek Gite. (14 Mar 2006). "Howto: Linux Add User To Group" Retrieved 17 Jan 2011.
- ↑ "untar multiple files"
- ↑ http://www.computing.net/answers/programming/count-number-of-files-in-directory-/15868.html Retrieved 5 Apr 2011.
- ↑ http://archives.unixforum.co.uk/showtopic147.html Retrieved 21 Jul 2011.
- ↑ http://www.manpagez.com/man/1/killall/
- ↑ Jeff Hunter. (18 Sep 2010). "Which Linux Version / Build / Distribution am I running?" Retrieved 17 Jan 2011.
- ↑ (2 June 2008). http://fixunix.com/redhat/340630-32-bit-64-linux-version.html Retrieved 17 Jan 2011.
- ↑ Mark D. Roth. "Command Line Stuff" Retrieved 12 May 2011.

