Linux tips collection

2013/12/08 by Lassi A. Liikkanen

Linux tips

Specifically for Fedora Core / Redhat Enterprise Linux / CentOS, but might work with other distributions also

Retrieving multiple PDF files from web and joining them on command line
Say you have collected a list PDF file URLs to a text file called URL.txt to an otherwise empty directory. You would like join these files together and merge into a single PDF. Try the following commands to first retrieve and then merge files, in this case it is assumed that file are numbered from 0-9999:
wget --input-file=URL.txt
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=MERGE_Output.pdf ????.pdf
How to create animation videos from still images?
You can easily collate large amount of still into an animation with mencoder or ffmpeg. Try the following syntax:
mencoder mf://*.jpg -mf fps=25:type=jpg -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi -ffourcc DX50

ffmpeg -i %02d_frame.png frames.mp4

Should you want to do something on the pictures before you create a video out of them, try convert. The following code example shows how to crop images to a custom size (560x800) with an +50px offset to the right from left upper corner. The output png files have 256 color palette and are renamed to have a c. prefix in this batch command:
find . -name '*png' | xargs -l -i basename '{}' | xargs -l -i convert -crop 560x800+50+0 -type palette '{}' 'c.{}'
What's mounted?
Try plain mount (essentially /etc/mount) or see /proc/mounts
Where is my LVM partition?
LVM partitions may not be automatically mounted when you load a Linux from a live disk. It must be mounted manually from /dev/mapper/Volume00-LogVol00 which will work as expected, but requires a mount point. E.g.:
mount /dev/mapper/Volume00-LogVol00 /mnt/lvm1
What system am I running
Running uname -a shows which kernel you are using along with some other machine specific info. Even more (irrelevant) information can be extracted from kernel by running /sbin/sysctl -A. The CPU can be identified by reading /proc/cpuinfo, integrated devices are shown by /sbin/lspci -v
What services are running?
The complete, generic list of all available services and related ports is under /etc/services but more accurate machine-specific info comes from /sbin/services --status-all
Which RPMs/packages are installed
Most easily with rpm rpm -qa | less or a bit slower option: yum list installed | less
What to do with VI(M)
VIM editor is a part living ancient computer history when you had to know the commands before being able to do anything. To get started with visudo (how to used visudo is a longer story), for instance, try i (enters insert mode to edit file normally), ESC returns back to command mode and :wq saves your changes and quits.
How schedule tasks
To run reboot just once the next morning, give command at 06:00 and type the command reboot. Use atq to check that the job was accepted. To execute a program called emptytemp every morning, use crontab, which allows everyone setup their own scheduled jobs. For admin, /etc/crontab contains the global cron control, which can be used to setup custom cron jobs at desired times. Alternatively, the directories under /etc/cron.*/ can be used if the default scheduling is fine
How to find and kill processes and programs
You can display all processes, sorted by their total execution time load by
ps -ef | sort -k6 ps -ef | sort -k6
If you a program that has likely hung up, so you should kill it. If you're root, substitute for the user who owns the process, for instance:
su homer -c 'kill -TERM -1'
The -1 stands for all processes owned by the user. If TERM is ineffective, use KILL.
How to manage quotas?
Managing quotas is quite tricky, requiring some preparation (see RHEL documentation. When quotas are properly setup for the filesystem, you need to enable them at runtime by
quotaon -vaug
and set for each user by
setquota -u iimeli 3000000 6000000 0 0 /dev/md3
This is the annoying part - you'll have to do this manually for each new user. With a lot of new users, you might need to devise script for automatically setting system specific quotas for the user. Ensure your settings work by running report: repquota /home
How to add new users?
New users should be added with adduser. However, you must consider also: group memberships, quota, sudoers for upgraded access (/etc/sudoers) and login options. For instance, it is a security threat to allow login for all user accounts. Set the option AllowUsers or AllowGroups in /etc/sshd/sshd_config. It is unnecessary to use DenyUsers because only allowed users can login.

In general, you might also like to setup global hosts.deny and hosts.allow if you're directly connected to net.
How to update or create SSL certificate for httpd?
In normal circumstances, you'll receive the key automatically from your identity provider (signer, or certificate authority), but if you're using a self-signed certificate you need to generate a key and create a certificate yourself. Do the following:
cd /etc/httpd/conf
/usr/bin/openssl genrsa 1024 > ssl.key/server.key
cd /usr/share/ssl/certs/
make testcert
service httpd restart
If you wish to use a passphrase, run make serverkey script instead of openssl rsa generator
How to check a hard drive?
Normally, you can use different fsck utilities to chekc your file system integrity. However, if you suspect your hard drive is badly, physically damaged, you may resort to badblocks which allows you to run write-read testing to the disc. Warningn this permanently erases everything on the disc! To do this try
badblocks /dev/hdX -b 2048 -c 512 -s -v -w
preferably in safe or rescue mode with only the particular drive mounted
How to adjust system time settings
Normally, system time settings (time zone etc.) should be set when installing the operating system. Also, the drift that naturally occurs in BIOS (motherboard) clock is compensated by the network time protocol (NTP) daemon. However, if you sometimes discover that your time has drifted badly, check the following.

Adjust clock time settings in /etc/sysconfig/clock and check your timezone, which affects Day Light Savings settings. Also, turn on UTC and set your BIOS clock to Universal mean time (GMT) using command
/usr/sbin/hwclock --set --date='12/31/07 23:59:59'
Now, you must next update your system (OS) time by the command
/usr/sbin/hwclock --hctosys --utc
If your NTPD is running correctly, your system clock should be now up to date (for more details, see
Some useful commends for NTP:
service ntpd stop
#force adjust ntpdate -b
service ntpd start
ntpq -p
How to change BASH prompt?
Individual users can change their prompt by setting environment variable PS1 in their initialization file ~/.bash_profile or ~/.bash_rc. If you would like to set a system-wide default value for the prompt, use /etc/profile. You can also experiment with different prompt styles dynamically by the command:
export PS1='[

Related content:
Bash Shell Script to resolve destinations of T.Co hyperlinks created by Twitter to proper URL , 2013/10/02

Command line script to batch rename files in UNIX shell, 2010/01/06

Practical guide to using SSH public key identification, 2008/06/25

No comments for this page:
Add comment | Show all comments

Your email will not be shown publicly or disclosed to third parties, it is used to validate messages
Location (City, Country):
* This information must be provided

Keywords: [unix] , [computers] Document's status: Ok (Document dates explained)

This document created: 2007/03/07
Modified: 2013/12/08
Published: 2012/12/09

This document's permanent URI (linking):

© Lassi A. Liikkanen 2007 - 2021. All rights reserved.
^Top of the Page^

*Change layout:
Printable printable
Large text


@lassial Twitter feed: