User Tools

Site Tools



Modify swappiness

Swappiness accepts values between 0-100 (At 100, the kernel will always prefer to find inactive pages and swap them out)

cat /proc/sys/vm/swappiness # check it
sysctl vm.swappiness=10 # modify it

Or modify /etc/sysctrl.conf and add a line with


Getting Hardware Info

Console utilities:

dmidecode -q | less
lshw | less
lshw -short
cat /proc/cpuinfo # etc...

or graphical: HardInfo

Monitor Internet Connections

netstat -tpe

  • -t show only TCP connections
  • -p displays PID and NAME for the program who makes the connection
  • -e extra information

To create a hardlink, you can use ln command. For example, we have a testa.txt file and we want a hardlink to it. First:

$ cat testa.txt
$ stat testa.txt
  File: `testa.txt'
  Size: 6               Blocks: 16         IO Block: 4096   regular file
Device: 801h/2049d      Inode: 2711019     Links: 1
Access: (0644/-rw-r--r--)  Uid: (  500/ncristian)   Gid: (  100/   users)
Access: 2009-04-09 17:21:47.000000000 +0300
Modify: 2009-04-09 17:21:44.000000000 +0300
Change: 2009-04-09 17:21:44.000000000 +0300

Then, create a hardlink called testb.txt

$ ln testa.txt testb.txt
$ ls -l test*.txt
-rw-r--r-- 2 ncristian users 6 Apr  9 17:21 testa.txt
-rw-r--r-- 2 ncristian users 6 Apr  9 17:21 testb.txt

Both files will have the same content, but if you delete one of them, the other one will remain intact. The number 2 in the 'ls' listing, shows us how many hardlinks are for the same content (in our case 2, testa.txt and testb.txt).

Let's suppose that you have these files in separate locations. Not our case, but how you can find them all? Simple…

  • findout what inode have one of them (unique for all) and look after it:

ls -i testa.txt
2711019 testa.txt
find / -inum 2711019

  • use directly find command with samefile arg:

find / -samefile testa.txt

Encrypt a file with vim

vim -x file

The -x flag will prompt for a password. Without this password, the file looks like gibberish. Pretty cool, hey? NOTE: this is a simple crypt-based encryption mechanism built in. Don't rely on it for very sensitive data.

For even less security, while editing a file with vim you can encrypt/decrypt using the worldwide standard ROT13 encryption. After opening a file in vim, use “ggg?G” (three g query cap-G) to ROT13 the entire file, “g?g?” to ROT13 a single line. See “:help rot13” details.

For strong encryption, vim has a plugin who allows to work directly on encrypted files (gpg): just asks for the password when you try to open an encrypted file, and then edits and saves as a normal text file. This way, you avoid opening (decrypting) the file in an unsafe environment, and then re-encrypting the file.
Install: download the plugin, and put it in .vim/plugin folder from your home directory.

Read a CD volume label

To read the volume label of a CD-ROM from the terminal:

$ dd if=/dev/cdrom bs=1 skip=32808 count=32
SG8                             32+0 records in
32+0 records out
32 bytes (32 B) copied, 0.00195546 seconds, 16.4 kB/s

Label was in this case SG8. Please note that /dev/cdrom can be different on your computer (e.g. /dev/cdwriter, etc)

Count the files in a directory

ls | wc -l

It doesn't count the . and .. (current and parent) directories.

Use SSH to execute remote commands

Use: ssh user@host '<command>'

# example
ssh root@ 'df -h'

Create ISO from files and directories

mkisofs -J -r -o <output.iso> <directory to be burned>

-R or -r options will enable RockRidge
-J add Joliet names

Send a file over network using netcat

On sending machine (for example - port 3333 chosen randomly)

cat file.tar.bz2 | nc -l 3333

On receiving machine:

nc 3333 > file.tar.bz2

Note: this is an UNENCRYPTED transfer over the network. If you want secure transfer, use scp utility.

Using yum locally

If you want to use yum (centos, redhat) to install a local package, use this:

yum localinstall /path/to/local.rpm

Additionaly, you can add –nogpgcheck if the package is unsigned.

Check status → hdparm -C /dev/sdX
Get info about disks → hdparm -I /dev/sdX
Activate power management on disc → hdparm -B 1 /dev/sdX (check man for -B values)

Erase a CD-RW from CLI

First, check where you have the CDRecorder with wodim:

# wodim --devices
wodim: Overview of accessible drives (2 found) :
 0  dev='/dev/scd0'	rwrw-- : 'HL-DT-ST' 'DVD-ROM GDR-H30N'
 1  dev='/dev/scd1'	rwrw-- : 'ATAPI' 'iHAS120   6'

Then, erase the disc:

# cdrecord blank=fast dev=/dev/scd1

linux/var_commands.txt · Last modified: 2013/03/16 17:40 (external edit)