Handy Linux Commands
This is a list of handy linux commands (and sites) with sources.
TOC
- Bash Prompt Customisations
- Change/Add SSH Port
- Check disk space
- Check distribution information
- Check kernel version
- Discover disk volume information
- mogrify — Comand-line image editing
- wget
- Add datestamp to filenames
- Change file datestamp with touch
- Discover IP address of local computer
- Updating Dyndns addresses with ddclient
- Patch Kernel
Bash Prompt
Here’s a site with more than you ever wanted to know about modifying the bash prompt: http://www.linuxselfhelp.com/howtos/Bash-Prompt/Bash-Prompt-HOWTO.html
Change/Add SSH Port
Comment
- Edit
/etc/ssh/sshd_config
. - Add the desired port in the section
[Ports]
. - Reload
/etc/init.d/sshd
Source
http://forums.spry.com/showthread.php?t=98"
Check Disk Space
Command
df
or (for human units)
df -h
Output
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 29063196 4422116 23176356 17% /
varrun 1031260 132 1031128 1% /var/run
varlock 1031260 0 1031260 0% /var/lock
udev 1031260 60 1031200 1% /dev
devshm 1031260 56 1031204 1% /dev/shm
lrm 1031260 39976 991284 4% /lib/modules/2.6.24-21-rt/volatile
/dev/sdb1 197572288 52957424 134657780 29% /home
/dev/sda2 43598860 928936 40472636 3% /var
or with @-h option:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 28G 4.3G 23G 17% /
varrun 1008M 132K 1007M 1% /var/run
varlock 1008M 0 1008M 0% /var/lock
udev 1008M 60K 1008M 1% /dev
devshm 1008M 56K 1008M 1% /dev/shm
lrm 1008M 40M 969M 4% /lib/modules/2.6.24-21-rt/volatile
/dev/sdb1 189G 51G 129G 29% /home
/dev/sda2 42G 908M 39G 3% /var
gvfs-fuse-daemon 28G 4.3G 23G 17% /home/dan/.gvfs
Additional common options
If you give the file name of a device (e.g. /dev/sda1), output will be restricted to that device. See man df
for a list of more obscure and specialised options.
Comment
Forevergeek has a handy script:
#!/bin/sh
DISC=$1 PARTITION=`df -h |grep $DISC |awk ‘{print $1}’` SIZE=`df -h|grep $DISC|awk ‘{print $2}’` USED=`df -h|grep $DISC|awk ‘{print $3}’` FREE=`df -h|grep $DISC|awk ‘{print $4}’`
echo “Partition: $PARTITION” echo “Total size: $SIZE” echo “Used space: $USED” echo “Free space: $FREE”
Presumably this could be modified to accept human disk names, as well.
Source
http://forevergeek.com/linux/check_disk_space_in_linux.php"
Check Distribution Version
Command
lsb_release -a
Output
Distributor ID: Ubuntu
Description: Ubuntu 8.04.1
Release: 8.04
Codename: hardy
Additional common options
-i, --id Display the distributor’s ID.
-d, --description Display a description of the currently installed distribution.
-r, --release Display the release number of the currently installed distribu‐ tion.
-c, --codename Display the code name of the currently installed distribution.
-a, --all
Comment
This provides certain LSB (Linux Standard Base) and distribution-specific information. It doesn’t seem to provide kernel information (see uname).
Source
http://www.cse.psu.edu/~lstclair/Howtos/release.html. See also man page
Check kernel version
Command
uname -r
Output
2.6.22-14-generic
Additional common options
-a, --all print all information, in the following order, except omit -p and -i if unknown:
-s, --kernel-name print the kernel name
-n, --nodename print the network node hostname
-r, --kernel-release print the kernel release
-v, --kernel-version print the kernel version
-m, --machine print the machine hardware name
-p, --processor print the processor type or "unknown"
-i, --hardware-platform print the hardware platform or "unknown"
-o, --operating-system print the operating system
Comment
This checks the kernel version, but even with the -a option doesn’t provide the distribution information (for which see: lsb_release).
Source
None. See man page.
Discover Volume Information
Command
vol_id /dev/sdb1
Output
ID_FS_USAGE=filesystem
ID_FS_TYPE=ext3
ID_FS_VERSION=1.0
ID_FS_UUID=1384715c-0842-45eb-ac19-6da68568aaa3
ID_FS_UUID_ENC=1384715c-0842-45eb-ac19-6da68568aaa3
ID_FS_LABEL=
ID_FS_LABEL_ENC=
ID_FS_LABEL_SAFE=
Additional common options
-u Display UUID only
Comment
UUIDs are now used to identify volumes in things like /etc/fstab; by identifying them by UUID instead of dev, you don’t have the problem of disks changing name if they are installed in a different order next time.
Source
http://ubuntuforums.org/showpost.php?p=1942898&postcount=8":
mogrify Command line image editing
Command
mogrify {options} filename
Output
Mogrify overwrites the original image unless you specify a path option. It always uses the same file name unless you change it with an extension.
Use -path – to write to standard input or output
Additional common options
-scale xx%
-path
Comment
This is part of imagemagick.
Source
wget
Command
wget {options} URL
Output
Wget gets remote files and copies them to output file. Use -O -
to write to standard output.
Additional common options
Comment
Source
Add datestamp to filenames (bulk)
from: http://www.linuxquestions.org/questions/linux-newbie-8/script-add-date-to-filename-188760/
# script=dname
#parameter $1 is the existing file name
dt=`date +%y%m%d`
mv $1 $1$dt
Change file datestamp with touch
touch -t 199903190000 *
(Changes all the files in a given directory to datestamp 19990319T0000)
Discover IP address of local computer
from: http://ubuntuforums.org/showpost.php?p=1133053&postcount=2
ifconfig / iwconfig
or
ip addr show
or
ip route
Update DynDNS addresses with ddclient
From: http://www.dyndns.com/support/kb/using_ddclient_with_dyndns_services.html http://ubuntuguide.org/wiki/Dynamic_IP_servers and https://help.ubuntu.com/community/DynamicDNS
Patching Kernel.
This method worked well for me, except that in the last couple of steps, the names weren;t obviously what the discussion led me to believe (the .deb files had very long extensions and the files in /lib/modules/
used – rather than + as the connector. I’m also not sure that I ended up with the most recent kernel—I need to discover how the number in the kernel revisions system works. When the patching was over and I rebooted, the appearance was different.