If you want to carry out a task but you are not sure which command to use, try using 'apropos' followed by a description of your task and it will list out some appropriate commands. For example apropos "copy file"
When you delete a file, linux will scan all the data. If you want to delete a very large file, and some files can grow to hundreds of gigabytes, this will generate lots of IO and lock out your session for a long time. Instead of using 'rm' to delete the file, simply write a zero input to the file, which will essentially wipe it like this > /path/massive_file.log
You can use cd .. to go up a directory, but did you know you can also use cd - to go down a directory
If you want to run a command, and leave that command running when you close the terminal window, prefix the command by nohup, which stands for 'no hang up'
If you use rm to remove a file, the underlying data still exists. To securely delete a file use shred. shred -zv filename. Obviously, this command must be used with caution as there is no way back. The -zv options mean overwrite with zeros then truncate and remove the file when complete.
This is not meant to be an exhaustive list of Linux and UNIX commands, there's plenty of sites out there that will give you them. Rather, it's a list of some of the commands that I find useful when working with Linux and UNIX Storage. While UNIX and LINUX commands are often identical, here is a list of some of the commands that differ.
|Action||AIX UNIX||SUSE Linux|
|Listing physical volumes||lspv||pvdisplay|
|List partitions in a disk||lspv -l <disk>||fdisk -l <disk>|
|List volume groups||lsvg||vgdisplay|
|Create volume group||mkvg||vgcreate|
|Remove volume group||rmvg||vgremove|
|Add a physical volume to volume group||extendvg||vgextend|
|Remove a volume group definition||exportvg||vgexport|
|Remove a physical volume from volume group||reducevg||vgreduce|
|Import a volume group||importvg||vgimport|
|Activate a volume group||varyonvg||vgchange|
|List logical volumes||lslv||lvdisplay|
|Create a logical volume||mklv||lvcreate|
|Grow filesystems with a logical volume||chfs||resize_reiserfs and resize2fs|
|Shrink filesystem||chfs||resize_reiserfs and resize2fs|
|Network interfaces||netstat -in||ifconfig|
|Network routes||netstat -rn||netstat -rn, route|
|staticroutes||smitty route||/etc/sysconfig/routes (SUSE)
First, what should be some basic ideas about how to interface with Linux and UNIX. Be aware that some Utility commands are shell dependent. These ones should work for the ksh shell. Every user has their own environment that contains variables that control your session, such as home directory, shell and paths to commands. Use the command 'env' to see what variables are set for your session. Unix commands are more or less standard, but there are many flavours of Linux. Some Linux variants have additional commands specific to that flavour. These commands should work for Red Hat.
To make temporary changes to your environment use the set command as above 'set -o vi' or 'set history=50' (this increases your history record from the 20 default).
To make permanent changes you need to update the .profile dataset in your home directory. You can see this file if you use the ls -al command.
This leads to Unix editing. The vi editor is pretty much universal and is powerful once you learn to use it. Some less well known command mode tips are: -
One of the challenges with TSM backups is network connectivity. These network commands are worth trying to track down a problem, before you go and find someone who knows what they are doing.
/home/stmanl:(no-env):/users/cn082337 $ host 10.125.228.207
s12365dev328-csm is 10.125.228.207, Aliases:
/home/stmanl:(no-env):/users/cn082337 $ host dev328
s12365dev328-csm is 10.125.228.207, Aliases:
/home/stmanl:(no-env):/users/cn082337 $ lsattr -El sys0 -a realmem
realmem 8388608 Amount of usable physical memory in Kbytes
The lspv command with various flags will list physical volumes and various attributes, not all of which are relevant in these days of RAID arrays and virtualisation. Try man lspv for an explanation.
The lsvg command for Volume Groups is relevant for HACMP configurations where you need to know the filespaces that are assigned to to floating HACMP volume groups.
/home/stmanl$ lsvg -o
The Linux command for this is not the same as Unix, to check installed tivoli software on AIX use
lsppp l- *tivoli*
and on Linux (RHEL) use this command. The -i switch means the search will not be case sensitive
rpm -qa | grep -i tivoli
The VMSTAT command can be used to check for disk bottlenecks by looking at the block I/O. A command with typical parameters would be
vmstat -ItW 10
The -ItW means show an IO view, add a timestamp on the end of each time and display the count of waiting threads. The '10' means run the command every 10 seconds. The commands has loads of other parameters as well as these three. Typical output looks like this.
The first 4 columns are the most interesting;
'r' is the runber of 'runnable' kernel threads, including active and waiting
'b' is the number of threads that are blocked waiting for IO on filesystems
'p' is the number of threads waiting for IO on raw logical volumes
'w' is the number of threads waiting for IO operations
You want to see Values of 0 in the 'b' 'p' and 'w' columns. If you see values greater than 0, this indicates the I/O threads that are blocked but don't worry about occasional high values, this is only an issue if the values are consistently high.
IOSTAT output can be used to check for Disk performance bottlenecks, suitable commands for AIX and Linux respectively are
iostat -DlT 10
iostat -xtk sinterval iterations
This command will return loads of data for every online disk, split into 4 sections; xfers, read, write and queue.
The qfull column in the queue section indicates how many times an i/o request was blocked because the OS queue for the disk was full. Consistently high numbers are bad and is an indication that there isn’t enough parallelism at the OS layer, or it might be an indication that queue depth is incorrectly set. Most IBM disk subsystems have a default queue depth of 32, the XIV can be set at 64, but non IBM disk subsystems have a default value of 1. For parallelism it can be better to have 10 100GB LUNS rather than 1 1TB LUN.
The tps column under xfers tells you hom many IOs per second (IOPS) are going to each disk, and typical Fibre Channel or SAS IOPS should be about 150, SATA about 90 IOPS, but SSDs should be in the thousands.
The read and write columns are service times, and TSM likes service values less than 5ms for log and DB reads or writes.
Use the locate to find in which directory a specified file is located. The Syntax is locate filename. You can use wild cards in the file names. However, this command does no search down the directory structure, it uses a database of filenames. The issue is that locate is unable to find any files created after the latest update of its database. You can update this database if you are logged on as root with updatedb command. It is best to run the command in the background by appending an ampersand (&), so you can immediately continue working on the same command line (updatedb &).
The find command will search for a file in a given directory, which is not so useful, unless you are running it as part of a script to check that a file exists. The advantage is that itscans the actual directory. You can also use wildcards to search for similar files.
Use the commands mkdir and rmdir to create and delete a directory. A new directory will be created as a subdirectory in whichever directory you were sitting in when you issued the command. The rmdir command will delete the specified directory, provided it is already empty. This cn be a real problem if you want to delete say a code download, it is a real pain to have to start with the lowest directory, delete the files, then remove the directory and work your way up the path. You will also hit problems with hidden files. You can use the rm -r directory_name, which is a recursive delete and will delete the directory, all sub directories and files, but be very careful with recursive deletes and do NOT use wildcards as you could delete a lot more data than you planned.
If you need to create a new blank file, use touch filename. To delete a single file, use rm filename. If you use the -i option, rm -i filename, then you will get a 'do you really want to' confirmation message before the file is deleted.
To move a file use mv [-b -i] file_name To_path_and_file_name. If you use the -b option, then Linux will create a backup copy of the sourcefile before moving, as the from file will be deleted.
To copy a file use cp [-i -r] file_name To_path_and_file_name. The -r option is used for directories and means copy recursively, eg include subdirectories.
cat filename is useful for displaying the contents of a small file. For larger files, consider using
less filename. With this command you can scroll down a file with the space bar, or go up and down half pages with PgUp and PgDn. You can jump to the beginning or end of a file using Home and End. You use Q to exit the program.
tail -100 filename will display the last 50 lines of the file. This is particularly handy for checking out the end of log files.
You can use grep to search for a string inside a file. The syntax is grep [-i] searchstring filename If the search string is found, the command displays the line in which the searchstring was found along with the file name. The -i parameter means Ignore case
When you create a file, the file is owned by the userid that you were logged in with. You can change this with the chown command. chown username groupname filename for example chown oracle oinstall You use chmod to change the permissions of a file. The permissions are in 3 parts, user, group, others. The permissions are often made as numbers, where 7 means execute, 6 means write, 5 means read and execute, 4 means read and 0 means no permission. So for example
chmod 755 PBW_tdpo.opt means full acccess for the owner and read/execute for everyone else.
chmod 644 PBW_tdpo.opt means write acccess for the owner and read for everyone
chmod 666 PBW_tdpo.opt means write acccess for all
ps will report on current processes and can be piped with grep to find specific processes. For example to see what tsm processes are running use ps -ef | grep tsm
The su command makes it possible to log in under a different user name from a running session. You would never log into a server directly with root, but sudo to root once logged in su root. Once you are logged into root, you can then sudo to any other userid without needing a password. This is useful for checking that things like file permissions have been set correctly, but be aware that if you just use su on its own, the new userid will inherit the environment variables from root. To pick up the correct environment variables you need to use, for example, su - oracle. To get back to root use exit.
Once you start jumping around different userids, its easy to forget which one you are now logged in as. The whoami command will help you remember.