Linux commands

From Wsms

Jump to: navigation, search

Examples of commands and simple scripts in bash.


Contents

mkfs.vfat

You can make a FAT partition with the mkfs.vfat command. FAT partitions can be read and written by both Linux and Windows. The maximum file size is 2.0G, and FAT does not support Linux or NTFS file ownerships and permissions.

# mkfs.vfat -v -n SHARE /dev/hda6

This command formates the sixth partition of the first IDE hard drive. The volume name, or label, will be SHARE. The -v is the verbose flag. Only the root user can use the mkfs.vfat command.


nconnections.sh

This simple shell script lets you keep an eye on how many users are watching your screen 0 using vncviewer. See Xvnc_Fedora_setup_howto

#!/usr/bin/env bash
# George Geller
# 20061027
# Show how many connections we have to our port 5900.
NCONN=`netstat -ant | grep 192.168.1.12:5900 | wc -l`
echo -n "$NCONN connections"

You have to replace 192.168.1.12 with the IP address for the interface where users connect. Then you can run watch:

$ watch ./nconnections.sh

find

Find all files, or just ones that are interesting. List them, or do something with them.

Find all files in /etc directory newer than ten minutes old:

# find /etc -mmin -10 -print

Find all files in /etc directory newer than one day old:

# find /etc -mtime -1 -print

Find all the .wmv files and get a long listing:

# find / -name "*.wmv" -exec ls -l '{}' \;

Find all the files in your home directory and save the list to another file:

# find ~ -name "*" -print > find.out

Find all the files that are symbolic links:

# find . -type l -print

Keep a hard disk like the Seagate_FreeAgent somewhat busy so it doesn't go to sleep or something:

# nice find /mnt/sda3/ -type f -exec cat '{}' > /dev/null \;

List empty directories:

$ find -type d -empty

Remove empty directories:

[ggeller@arthur George]$ find -depth -type d -empty -exec rmdir '{}' \;

Prettify the output by removing the initial ./:

ggeller@arthur:~$ find . -name "*.log" | perl -ne 's/^.\/// ; print'

tunnel with ssh

This sets up an ssh tunnel from a port on wsNN to a port on rop.

[user@wsNN ~]$ ssh -f -N -L 5901:localhost:5901 user@rop.ncc.sdccd.net

kill

kill is the Linux command to send a message to a process, or to kill it:

[user@arthur ~]$ kill -9 <pid>

Use something like pstree -pu to get the pid for the process that you need to kill. You can use different integer values to send different messages. kill -l (for list) prints a list of the possible messages.

[ggeller@arthur ~]$ kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
 5) SIGTRAP      6) SIGABRT      7) SIGBUS       8) SIGFPE
 9) SIGKILL     10) SIGUSR1     11) SIGSEGV     12) SIGUSR2
13) SIGPIPE     14) SIGALRM     15) SIGTERM     16) SIGSTKFLT
17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU
25) SIGXFSZ     26) SIGVTALRM   27) SIGPROF     28) SIGWINCH
29) SIGIO       30) SIGPWR      31) SIGSYS      34) SIGRTMIN
35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3  38) SIGRTMIN+4
39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12
47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14
51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10
55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7  58) SIGRTMAX-6
59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX

The meaning of most of the values is an advanced topic. You can get a little information about them from man kill, man signal, and man signal.h

wget

wget fetches files(s) from the internet to your current working directory. To get an rpm file:

[ggeller@arthur ~]$ wget http://prdownloads.sourceforge.net/webadmin/webmin-1.300-1.noarch.rpm

To get an entire website:

[ggeller@arthur ~]$ wget -r http://www.buckysicecream.com

The -r option generally works for static web sites, but not so well for dynamic sites. wget works with the http and ftp protocols. It doesn't work for sites that required logins.

rsync

Efficiently copy stuff. rsync is great for synchronizing stuff over the web. Copy everything from your directory on the rop server to your home computer:

[ggeller@arthur ~]$ rsync -av georgeg@rop.ncc.sdccd.net:
georgeg@rop.ncc.sdccd.net's password:
receiving file list ... done
./
.ICEauthority
.Xauthority
.bash_history
.bash_logout
.bash_profile
...

See also rsync with ssh keys

stat

Stat is a command that shows a few things that ls -l doesn't:

[ggeller@ws05 ~]$ stat RMAIL
  File: `RMAIL'
  Size: 183             Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 1372178     Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  500/ ggeller)   Gid: (  500/ ggeller)
Access: 2007-02-06 11:17:58.000000000 -0800
Modify: 2007-02-06 11:10:42.000000000 -0800
Change: 2007-02-06 11:10:42.000000000 -0800

ntpd and ntpdate

ntpd is the ntp deamon. It is supposed to keep the time on you Linux box synchronized with reliable time sources over the internet. ntpd doesn't seem to work very will on virtual machines running VMWare. ntpdate is a one-shot version (more or less) of ntpd. The most common way to use ntpdate is:

[root@localhost ~]# service ntpd stop
Shutting down ntpd:                                        [  OK  ]
[root@localhost ~]# ntpdate pool.ntp.org
15 Mar 16:10:22 ntpdate[2902]: step time server 216.165.129.244 offset 199.609837 sec
[root@localhost ~]# service ntpd start
15 Mar 16:10:40 ntpdate[2910]: step time server 64.34.193.47 offset 6.367052 sec
Starting ntpd:                                             [  OK  ]

games

There are some Linux games available:

Tuxracer
Scorched 3D
Doom/Quake

see also

http://www.linuxjournal.com/article/8412
20061215
ntpd
su
ping
nohup
Linux Commands/Find
gnome-volume-properties

Personal tools