Difference between revisions of "Linux Commands"

From GWAVA Technologies Training
Jump to: navigation, search
(rpm Package Installer)
 
(111 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
Useful Linux Commands
 
Useful Linux Commands
  
==Disk==
+
We use Suse linux (SLES) as one of the main OSs for our products.
 +
*[https://www.suse.com/documentation/ SLES documentation]
 +
*[https://www.suse.com/kb/ SLES Knowledge base]
  
gives you a quick overview of what disks are mounted and how full they are.
+
You can use <code>man [command]</code> to get information about a command, but that is more programmer oriented. You are generally better off going to a search engine and searching for <code>[command] examples</code>.
  
<code>
+
One of the great powers of Linux is being able to pipe <code>|</code> or redirect outputs from one command to another to do things.
 +
 
 +
Another thing is TAB complete is a useful tool, once you have a few characters in place you can press tab to complete the command or directory. Pressing tab twice quickly will show all other entries available.
 +
 
 +
You can also use these commands to create bash scripts. Save it as a script file "filename.sh" and give it execute rights "chmod +x filename.sh".
 +
 
 +
'''Superuser mode'''
 +
sudo [command]
 +
su -
 +
 
 +
'''Starting and Stopping Tomcat/mysql/apache'''
 +
 
 +
SLES11
 +
rcretain-tomcat7 start|stop|restart|status
 +
rcmysql start|stop|restart|status
 +
rcapache2 start|stop|restart|status
 +
SLES12
 +
systemctl start|stop|restart|status retain-tomcat7.service
 +
systemctl start|stop|restart|status mysql.service
 +
systemctl start|stop|restart|status apache2.service
 +
 
 +
==System==
 +
===Increasing the number of open files limits===
 +
By default SLES allows 4096 open files for a non-root user. This may be too small.
 +
 
 +
On linux in general you will have two places that you will need to look at in in increasing or decreasing the amount of open files that can be used.
 +
 
 +
1. First is the system wide limit. On SLES and most other Linux versions this is done in:
 +
 
 +
/etc/sysctl.conf
 +
 
 +
fs.file-max = desirednofiles
 +
 
 +
Then run:
 +
 
 +
sysctl -p
 +
 
 +
The sysctl -p reads the sysctl.conf file so you don't need to reboot for it to take effect. This doesn't work for all settings in sysctl, but it does work for maximim files.
 +
 
 +
2. The second limit setting is on a per user basis. This is important, because you may have a system wide maximum set quite high, but if your user is not listed here, it will have very small limit set of 4096.
 +
 
 +
To set this on SLES, you'll do the following:
 +
 
 +
(NOTE: this may be different on other linux distros)
 +
 
 +
First, edit the file:
 +
/etc/security/limits.conf
 +
 
 +
To set the number of limits for the tomcat user do the following:
 +
 
 +
tomcat hard    nofile 500000
 +
tomcat soft nofile   500000
 +
 
 +
Save the file, and reboot the server.
 +
 
 +
To verify the limits are correct, you can normally do this, but for tomcat in your instance I could not find a way to verify:
 +
 
 +
ulimit -Hn    (show hard limit, while logged in as whatever user you want to list the limit for)
 +
ulimit -Sn    (show soft limit, while logged in as whatever user you want to list the limit for)
 +
 
 +
3. Last of all, for the individual user limits, you need to make sure that /etc/pam.d/common-session has the following line:
 +
 
 +
session  required  pam_limits.so
 +
 
 +
==Disk Commands==
 +
 
 +
===df Disk Free===
 +
Returns a quick overview of what disks are mounted and how full they are in human readable formatting.
 
  df -h
 
  df -h
</code>
 
  
This is give you a total size of the directories under where this command was run and sorts by size. Warning can take a long time.
+
Sometimes a disk becomes full even though there appears to be plenty of room left. You may be out of inodes.
 +
df -i
  
  <code>
+
To determine the filesystem type of the volumes.
 +
  df -T
 +
 
 +
===mount Mount a file system===
 +
Mount a file system or device. You can also type mount by itself to show current mounts on the system. Before making the mount, make sure you have a directory on the Linux box to mount the filesystem to. Usually mounts go under the /mnt directory.
 +
 
 +
Create a mount point
 +
mkdir /mnt/whatever
 +
 
 +
Once you have the directory set up, you can now mount the filesystem or share.
 +
 
 +
Linux mounts use nfs usually:
 +
mount -v -t nfs 10.1.1.20:/exportdir /mnt/whatever
 +
 
 +
Netware mounts use npc usually:
 +
ncpmount -S [server] -A [IP address] -U [fully distinguished name] -V /vol1 /mnt -o tcp
 +
 
 +
NSS mount
 +
ncpmount -A 10.1.6.152 -S <serverName> -U <eDirectory FQDN> -H nfs -V <NSS volume name> /mnt/temp
 +
 
 +
Example:
 +
ncpmount -S school -A 192.168.100.1 -u admin.wwws  -V vol1 /mnt/nwserver -o tcp
 +
 
 +
Windows mounts can use cifs or samba:
 +
mount -t cifs //ntserver/download -o username=admin,password=password /mnt/whatever
 +
 
 +
mount -t smbfs -o username=admin,password=password //ntserver/download /mnt/ntserver
 +
 
 +
Note: Reload comes with some nice scripts that Tay created for setting up cifs and ncp mounts. They are found under /opt/beginfinite/reload/setup. You just enter the setup information into the corresponding conf file and run the script.
 +
 
 +
cifsmnt.conf:
 +
## Author: Tay Kratzer taykratzer@taykratzer.com ##
 +
## All values must be kept within double quotes. ##
 +
CIFS_USERNAME="administrator"
 +
CIFS_PASSWORD="windoze"
 +
CIFS_SHARE="share1"
 +
CIFS_SERVERIP="137.65.55.210"
 +
CIFS_RETRY_COUNT="10"
 +
CIFS_RETRY_SECONDS="30"
 +
LINUX_MOUNT_POINT="/mnt/winserver"
 +
 
 +
ncpmnt.conf:
 +
## Author: Tay Kratzer taykratzer@taykratzer.com ##
 +
## All values must be kept within double quotes. ##
 +
NCP_LOGIN_NAME="admin.acme"
 +
NCP_LOGIN_PASSWORD="novell"
 +
NCP_VOL="sys"
 +
NCPVOL_SERVERIP="137.65.55.210"
 +
NCPVOL_SERVERNAME="wwwfs1"
 +
NCPVOL_MAP_RETRY_COUNT="10"
 +
NCPVOL_MAP_RETRY_SECONDS="30"
 +
LINUX_MOUNT_POINT="/mnt/nwserver"
 +
 
 +
Once you've set up the conf file, run the script from the command line.
 +
 
 +
===umount Unmount filesystem===
 +
umount – Unmount a device or mounted filesystem.
 +
umount /mnt/whatever
 +
 
 +
Lazy unmount that allows the server to clear resources in the background once they are no longer busy
 +
umount -l /mnt/temp
 +
 
 +
===Check NFS version===
 +
Determine nfs version
 +
nfsstat -s (-s for server, -c for client)
 +
 
 +
==Directory Commands==
 +
 
 +
===cd Change Directory===
 +
Change directory. Tab complete can help traverse the tree.
 +
cd [destination directory]
 +
Change to root directory
 +
cd /
 +
go up one level
 +
cd ..
 +
..
 +
go up two levels
 +
cd ../..
 +
...
 +
 
 +
===du Directory details===
 +
Returns an estimate of file space usage, in human readable format (k,M,G). Warning: May take a long time.
 +
du -h
 +
 
 +
To get a human readable(h) summary(s) of a directory below the current directory.
 +
du -sh *
 +
 
 +
Returns a total size of the directories under where this command was run and sorts by size.
 
  du -hsx * | sort -rh | head -10
 
  du -hsx * | sort -rh | head -10
</code>
 
  
==List of files==
+
===md Create a directory===
This always works (show file size in bytes)
+
Creates a directory
 +
md [directory name]
 +
mkdir [directory name]
  
<code>
+
===cp -R Copy a directory===
  ls -s
+
Copy a directory recursively "R"
</code>
+
  cp -R [source] [destination]
  
This is a SLES alias of the above
+
===rm -r Remove a directory ===
 +
Removes a directory and its contents. Use -f if you need to force the issue. Warning: irreversible, fast and dangerous if done in the wrong place with wrong switches.[http://thenextweb.com/media/2012/05/21/how-pixars-toy-story-2-was-deleted-twice-once-by-technology-and-again-for-its-own-good/]
 +
rm -r [directory]
 +
rm -rf [directory]
  
  <code>
+
===l Directory List===
 +
Return a list of files in a directory. This always works (shows file size in bytes)
 +
  ls -s
 +
 
 +
This is a SLES alias of the above<sup>'''''*'''See Note below</sup>''
 
  l
 
  l
</code>
 
  
This shows the file size in human readable values (K,M,G)
+
The following command is an alias used in both SLES and Ubuntu as a shortcut for ls -l
 +
ll
  
<code>
+
Display file size in human-readable values "-h" (K,M,G)
 
  l -h
 
  l -h
</code>
 
  
==Download a file==
+
Sorted by size "S", ascending "r", human-readable "h"
 +
l -Srh
  
Download the Latest Version of Retain
+
Sorted by time "t", ascending "r", human-readable "h"
 +
l -trh
  
 +
Show hidden files "a", long list format "l", human-readable "h"
 +
l -alh
 +
 +
Sorted by reverse chonological order
 +
l -qaltr
 +
 +
Sorted by reverse order, human readable
 +
l -lhr
 +
 +
*'''''Note:''''' l ''is not recognized as an alias in Ubuntu, this is a SLES specific shortcut.''  ls ''and'' ll ''are generally universal.'' handy man page if you'd like to know more: http://man7.org/linux/man-pages/man1/ls.1.html
 +
 +
===lsof List Open Files===
 +
List all open files
 +
lsof
 +
 +
List files that are listening on port 5555
 +
lsof -i tcp:5555
 +
 +
lsof - “List Open Files”  Options I’ve found useful Include ports in use and what process is using them to how many files a process is using.
 +
 +
Example to find if a port is being used and what process is using it (including pid):
 +
testserver:~ # lsof -i {tcp/udp}:{port}
 +
 +
What it would look like in use:
 +
testserver:~ # lsof -i tcp:25
 +
COMMAND  PID USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
 +
gwvsmtp 3090 root    8u  IPv4  9498      0t0  TCP *:smtp (LISTEN)
 +
 +
If you want to see all the TCP/UDP info just use:
 +
testserver:~ # lsof -i
 +
COMMAND    PID    USER  FD  TYPE  DEVICE SIZE/OFF NODE NAME
 +
postgres  1652 postgres    3u  IPv4    6698      0t0  TCP *:postgresql (LISTEN)
 +
..
 +
..
 +
 +
Example of number of files open by a process (must know the PID before use):
 +
testserver:~ # lsof -p {pid of process} | wc -l"
 +
 +
What it would look like used:
 +
testserver:~ # lsof -p 30976 |wc -l
 +
1403
 +
 +
===find directory===
 +
Find a directory by name from the root
 +
find / -type d -name [folderName]
 +
 +
===chmod Change Permissions===
 +
Permissions are a big deal in Linux [https://en.wikipedia.org/wiki/Chmod] not so much in Windows.
 +
 +
Add the execute permission to all shell scripts in the current directory
 +
chmod +x *.sh
 +
chmod -R +x *.sh
 +
 +
Add read and write permissions to User and Group but only read to Other recursively "R" in the destination directory
 +
chmod -R 664 /[destination]
 +
 +
Add Execute, read, and write permissions to User and Group but only read to Other recursively "R" in the destination directory
 +
chmod -R 774 /[destination]
 +
 +
Add all the permissions
 +
chmod -R 777 /[destination]
 +
 +
===chown Change Ownership===
 +
Ownership of a directory can make a big difference in how Retain works
 +
chown user:group directory/
 +
 +
Change the ownership recursively "R" to user tomcat and group tomcat of the logs directory in the current directory
 +
chown -R tomcat:tomcat logs/
 +
 +
==File Commands==
 +
===cat Concatenate===
 +
Show the contents of a file
 +
cat "filename"
 +
 +
Pipe through more to display a screen full of text at a time (space for next page, enter for next line, ctrl-c to break out)
 +
cat "filename" | more
 +
 +
Pipe through less to display file in less.
 +
cat "filename" | less
 +
 +
===diff Find difference between files and directories===
 +
Compare two files
 +
diff file1.txt file2.txt
 +
 +
Show the difference between two directories and the files in each [http://linuxcommando.blogspot.com/2008/05/compare-directories-using-diff-in-linux.html]
 +
diff ~dir1 ~dir2
 +
 +
Show only the differences between directories by adding the q option. Add the r option to recurse down the directory structure
 +
diff -qr ~dir1 ~dir2 | sort
 +
 +
===Find a file, and other uses for the Find command===
 +
Find a file from the root of the file system (aka looks everywhere for it) Warning: may take a long time. [http://www.techrepublic.com/article/how-to-free-disk-space-on-linux-systems/]
 +
find / -name "fileName"
 +
 +
Find all files with the string "log" as part of the filename.
 +
find . | grep log
 +
 +
Find and recursively unzip all items in a directory structure called zippedDir to the current directory.
 +
find /zippedDir/-name "*.zip" -exec unzip {} \;
 +
 +
Find files in current directory older than 7 days and delete them.
 +
find . -mtime +7 -exec rm {} \;
 +
 +
Find any file off the root and beyond that is larger than 20M:
 +
find / -type f -size +20M -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'
 +
 +
Find 10 largest files starting at /(root)
 +
find / -printf '%s %p\n'| sort -nr | head -10
 +
 +
Find the number "wc" lines "l" of files "-type f" in a directory structure:
 +
find [directory]/ -type f | wc -l
 +
 +
Change all the files named “*.msgstorage” to *.msg.  I.E. file.msgstorage to file.msg in the current directory and children directories
 +
find . -name "*.msgstorage" -exec rename .msgstorage .msg {} +
 +
 +
Report all known instances of a command. A quick way to find out if something is installed.
 +
whereis [commandname]
 +
 +
===cp Copy file===
 +
cp origin /destination/file
 +
 +
To copy particular files recursively
 +
cp -r *.txt /destination
 +
 +
To copy to the current directory
 +
cp /software/origin.file .
 +
 +
===scp Secure File Copy===
 +
To secure copy a file from a remote location
 +
scp [username]@[source IP address]:/[source directory]/[source file] /[destination directory]
 +
To secure copy a file to a remote location
 +
scp [source] [username]@[destination IP address]:/[destination]
 +
 +
===rsync Remore sync===
 +
Sync a file or directory between locations, recurse "r" through subdirectories, retain "a" permissions, ownership and timestamps, verbose "v" logging to screen, show progress "P"
 +
rsync -ravP [source] [destination]
 +
 +
===mv Move file===
 +
Moves file to the destination directory in verbose "v" mode.
 +
mv -v "file" "destination"
 +
 +
===rm Remove or delete a file===
 +
Removes a particular file
 +
rm "file"
 +
 +
Remove all files older than 7 days
 +
find . -mtime +7 -exec rm {} \;
 +
 +
===chmod Change Permissions===
 +
Permissions are a big deal in Linux [https://en.wikipedia.org/wiki/Chmod] not so much in Windows.
 +
Add execute "x" rights to all levels on all shell scripts in the current directory
 +
chmod +x *.sh
 +
 +
===ln Symbolic link===
 +
Make symbolic links between files. This is useful if you need to change the log directory or repair a symbolic link that was removed.
 +
ln -s [path to new directory] ./retain-tomcat7
 +
 +
To remove a symbolic link
 +
rm linkname (without trailing /)
 +
 +
Get full link path
 +
readlink -f <symlink directory or file>
 +
 +
===Change UserID===
 +
List the users to get their userids
 +
cat /etc/passwd
 +
id [username]
 +
usermod -u [desired new userid] [username]
 +
 +
==Network==
 +
===wget Get File from website===
 +
Download the Latest Version of Retain
 
  wget "http://download.gwava.com/download.php?product=Retain&version=current"
 
  wget "http://download.gwava.com/download.php?product=Retain&version=current"
 +
SLES 12 tip: To give a file downloaded through wget an actual name instead of it giving it the URL name use the -O switch:
 +
wget “http://url/file.txt” -O name.you.want.to.give.file.on.disk.txt
 +
 +
===ifconfig Find IP Address===
 +
Find the IP address of the server. Use this command to find the IP address(es) and MAC address(es) the system uses. eth0 is the first NIC. If the system has multiple NICs, they are named, eth0, eth1, and so on. lo is loopback.
 +
ifconfig
 +
 +
===host Lookup DNS records===
 +
look up mx records
 +
host -t MX [domain.com]
 +
 +
Determine hosts
 +
cat /etc/resolv.conf
 +
 +
===ping Contact Server===
 +
Ping to see if a server is alive. Ctrl-c to stop.
 +
ping [ip address]
 +
 +
===DNS commands===
 +
DNS
 +
nslookup
 +
server
 +
dig [servername or ipaddress]
 +
 +
Clear DNS Cache by stopping and starting the service
 +
rcnscd stop
 +
rcnscd start
 +
 +
===traceroute Find route between servers===
 +
Trace the route to a server
 +
traceroute [domain.com]
 +
 +
===hostname Name of Computer===
 +
Show the system name
 +
hostname
 +
 +
===ssh Secure connection===
 +
Secure connect to another system, exit to leave ssh shell
 +
ssh [hostname or ip address]
 +
 +
===telnet Connect between servers===
 +
Useful for testing connections. You can send a test email with it:
 +
telnet [IP address or DNS hostname] [port]
 +
ehlo [ENTER]
 +
mail from:  retain@[your domain name]  (note: the "from" can actually be spoofed - it really can contain any text of user@domain.com)[ENTER]
 +
rcpt to: [yours or a user's email address][ENTER]
 +
data[ENTER]
 +
subject:  test email from telnet on Retain server[ENTER]
 +
This is a test[ENTER]
 +
.[ENTER]  (you are literally typing a "period" here and pressing [ENTER])
 +
quit[ENTER]
 +
 +
===netstat Network activity monitor===
 +
A useful tool for checking your network configuration and activity.
 +
netstat -lnp -A inet
 +
 +
To get port information
 +
netstat -A inet -n -p |grep [PID]
 +
 +
==Process Commands==
 +
===free Memory usage===
 +
Display memory usage
 +
free -m
 +
 +
===top System resources===
 +
Display an overview of the system resources can be used to find a process
 +
top
 +
 +
I/O statistics
 +
iotop -o
 +
 +
===vmstat Virutal Memory Statistics===
 +
Report virtual memory statistics: processes, memory, paging, block IO, traps, and cpu activity.
 +
vmstat
 +
 +
===swap space===
 +
See this article for determining swap space [http://www.cyberciti.biz/faq/linux-which-process-is-using-swap/]
 +
 +
===chkconfig Check runlevel===
 +
Check runlevel of a process
 +
chkconfig [process name]
 +
 +
===ps aux Find a process===
 +
To find a running process you know the name of
 +
ps aux | grep [process name]
 +
 +
===kill End a process===
 +
see find a process or top
 +
You have to find a runaway process with <code>top</code> or <code>ps</code>
 +
kill [process ID]
 +
It the process us hung you may have to be more forceful
 +
kill -9 [process ID]
 +
To kill all processes associated with a particualr name
 +
killall -15 [processname]
 +
 +
===w Who is logged in===
 +
Returns a list of logged in users if the TTY column shows "pts/3" that shows us that use is remotely logged in.
 +
who
 +
w
 +
 +
===fstab File system information===
 +
The fstab file will also contain information about any mounted filesystems as well
 +
cat /etc/fstab
 +
 +
===Find Linux Version===
 +
To find the SLES version of Linux that is installed use this command:
 +
cat /etc/issue
 +
"uname -r" (kernal build)
 +
cat /etc/*-release (all version info)
 +
 +
==Utilities==
 +
===CPU information===
 +
Provides detailed CPU information
 +
lscpu
 +
 +
===file system information===
 +
Provides detailed information about the filesystem
 +
df has a switch for that, and it is nicer when it is human readable
 +
df -Th
 +
Shows name, volume, file system type, and mount point. Also shows what volume is on what disk (pretty)
 +
lsblk -f
 +
Shows volume, uuid and file system type
 +
blkid
 +
 +
===history Command history===
 +
Get a history of commands
 +
history
 +
To run a past command
 +
![+number of command to run from history]
 +
To run a past command by name
 +
![Ctrl-r][start typing desired command]
 +
 +
===Checking disk performance===
 +
use the dd command[http://www.cyberciti.biz/faq/howto-linux-unix-test-disk-performance-with-dd-command/]
 +
 +
server throughput (write speed) write 1 GB to disk (this should be above 50MB/s)
 +
dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync
 +
 +
measure server latency (this should be above 1 MB/s)
 +
dd if=/dev/zero of=/tmp/test2.img bs=512 count=1000 oflag=dsync
 +
 +
 +
===tar Create archives===
 +
Create an uncompressed tape archive of a bunch of files
 +
tar -cvf [dest file name].tar [source directory]
 +
Extract a tar
 +
tar -xvf [filename]
 +
 +
===zip/gzip Compress files===
 +
Zip
 +
zip [dest file name] [source files or directory]
 +
Unzip
 +
unzip [file].zip -d /[directory]
 +
Create a gzipped tar file
 +
tar -czvf [dest file name] [source directory]
 +
Extract a gziped tar
 +
tar -xvzf [filename]
 +
Extract gzip
 +
gzip -dv [file name]
 +
 +
===clear Clear Screen===
 +
Clear Screen
 +
clear
 +
 +
===Screen command===
 +
Keeps a terminal session open even if the shell gets closed. Some tutorials [https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/][https://www.tecmint.com/screen-command-examples-to-manage-linux-terminals/]
 +
*To start a session:
 +
**In a terminal windows, type “screen” and press ENTER.
 +
*Hit CTRL-A to send a command to the “screen” session.
 +
*New window:  CTRL-A c
 +
*Move to next window:  CTRL-A n
 +
*Move to previous window:  CTRL-A p
 +
*To restore a session (if the terminal window gets closed): 
 +
**Login to a new terminal session.
 +
**Type: screen -r
 +
*To stop a session, simply type “Exit” in a terminal window.
 +
 +
===crontab Schedule Tasks===
 +
crontab – Schedule a command to run at a later time.
 +
 +
Each line in the cron (cron is the daemon) table follows the following format: 7 fields left to right.
 +
Field    Meaning   
 +
1    Minute (0-59)   
 +
2    Hour (2-24)   
 +
3    Day of month (1-31)   
 +
4    Month (1-12, Jan, Feb, ...)   
 +
5    Day of week (0-6) 0=Sunday, 1=Monday ... or Sun, Mon, Tue, Wed, Thur, Fri   
 +
6    User that the command will run as   
 +
7    Command to execute   
 +
 +
So, if you want to have Netcleanse restart the ntp-client to reset the time every hour, then you'd use this command:
 +
 +
This will load the crontab editor. Add the entry below, save the change and exit the editor.
 +
crontab -e
 +
Restarts ntp-client every minute
 +
0 * * * * root /etc/init.d/ntp-client restart
 +
Runs the script at the top of every hour
 +
00 */1 * * * /root/Desktop/gopostal/gopostalfullauto.sh
 +
 +
===date Date and time===
 +
This command can be used to display the current time on the server or adjust the time.
 +
date
 +
 +
===rcmysql MySQL control commands===
 +
To control MySQL services you can use these commands:
 +
rcmysql [start|stop|restart|status]
 +
 +
To determine the MySQL version, you can use one of these commands:
 +
mysql --version
 +
mysqlshow -V
 +
 +
===rcapache2 Apache control commands===
 +
To control apache services you can use these commands:
 +
rcapache2 [start|stop|restart|status]
 +
 +
===rcretain-tomcat7 Tomcat control commands===
 +
To control tomcat services you can use these commands:
 +
rcretain-tomcat7 [start|stop|restart|status]
 +
 +
===rpm Package Installer===
 +
Package installer. There are numerous useful flags that can be used with this command. For those flags, look here: http://www.novell.com/coolsolutions/tip/19918.html
 +
Most commonly, however, you'll just use the commands to install, upgrade and uninstall.
 +
rpm -ivh [filename].rpm
 +
 +
To uninstall
 +
rpm -e [filename].rpm
 +
 +
===shutdown Shutdown and reboot===
 +
Reboot the server
 +
reboot
 +
shutdown -r now (same as reboot)
 +
init 6 (not preferred)
 +
reboot -f (Last resort reboot method. The only time you'd want to use this option is if something is wrong with the init daemon.)
 +
 +
Shutdown
 +
shutdown -h now
 +
init 0 (last resort)
 +
 +
===telnet===
 +
Send a test message via telnet
 +
telnet x.x.x.x 25
 +
ehlo<enter>
 +
mail from: <test@test.com><enter>
 +
rcpt to:<validuser@yourdomain.com><enter>
 +
data<enter>
 +
subject: test<enter>
 +
testing <enter>
 +
.<enter>
 +
quit<enter>
 +
 +
and you should see a result similar to this:
 +
 +
220 g6postgres109.mydomain.com GWAVA Proxy Copyright (c) 2011 GWAVA, Inc. All rights reserved. Ready
 +
ehlo test.com
 +
250-g6postgres109.mydomain.com
 +
250-AUTH LOGIN
 +
250-8BITMIME
 +
250 NO-SOLICITING
 +
mail from:<test@test.com>
 +
250 OK
 +
rcpt to:<user4@mydomain.com>
 +
250 Ok
 +
data
 +
354 Start mail input; end with <CRLF>.<CRLF>
 +
subject: test
 +
testing
 +
.
 +
250 Ok
 +
 +
===watch process or command===
 +
Watch will repeat the command every 2 seconds for monitoring purposes
 +
watch "<command>"
 +
watch "ls -al"
 +
watch "ps aux | grep dbcopy"
 +
 +
Example: Command: telnet
 +
Example of watching DBCOPY, which Reload launches and sets up various ports depending on what it is doing (5001=user db copy; 5002=msg db copy, etc.)
 +
telnet 10.1.5.101 5001
 +
 +
While that telnet session is running, there are several commands that can be issued:
 +
* rff - request for file
 +
* rfc - request for the data
 +
* rfs - request for shutdown (will shutdown the computer)
 +
* rft - request for file (real time) - hit CTRL-] to break out of it.
 +
* frl - external library
 +
 +
 +
If you wish to change the iteration time from 2 second to 1 second up to 4200 seconds use the -n switch (you can either have a space or no space between the -n and the seconds you wish to iterate)
 +
watch -n30 "ls -al"
 +
 +
'''Advanced:'''
 +
The following will show the output to the command line and a log file:
 +
watch -t "(date '+TIME:%H:%M:%S' ; du -sh /file/path/you/wish/to/watch) | tee -a size.log"
 +
Notes: In the above command you could add the -n switch before or after the -t.  The file path on the du command is variable to what you want to watch, and the "size.log" can also be a file path.  For example you could put /var/log/retain-tomcat7/mylog.log.  The way it is in the above example it will write the log in the path that you run the command.
 +
 +
==Text Editing==
 +
===vi Text Editor===
 +
vi – Text editor for Linux. There are a variety of commands you can use in vi, here are some of the most useful:
 +
 +
To open a file:
 +
vi [filename]
 +
 +
*i: Insert text
 +
*ESC: Exit mode, for example, exit the insert text mode
 +
*/: Perform a search (n, repeats search; N, search backwards)
 +
*dd: Deletes a line
 +
*yy: Copies current line
 +
*yw: Copies current word
 +
*u: Undo last change
 +
*p": Pastes whatever was copied after the cursor position
 +
*:wq: Writes changes and exits vi
 +
*:q!: Quits without saving changes
 +
 +
For more details on using vi, look here: [http://staff.washington.edu/rells/R110/]
 +
It's better then edlin.
 +
 +
===less File viewer program===
 +
Less lets you view the contents of a text file by screenfuls.
 +
less [options] [filename]
  
 +
Options:
 +
*-g: Highlights just the current match of any searched string.
 +
*-I: Case-insensitive searches.
 +
*-M: Shows more detailed prompt, including file position.
 +
*-N: Shows line numbers (useful for source code viewing).
 +
*-S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
 +
*-?: Shows help.
 +
*+F: Follow mode for log.
  
==Find a file ==
+
Once in less there are a number of commands that you can use:
find / -name "httpd.conf"
+
*spacebar or page down: for next page
 +
*page up or b: for previous page
 +
*enter or j: for next line
 +
*k: for previous line
 +
*Shift-f: for follow mode. ctrl-c to abort follow mode.
 +
*g or <: Return to first line
 +
*G or >: Go to last line
 +
*/[text]: Forward search for [text]
 +
*?[text]: Backwards search for [text]
 +
*n: Next search match
 +
*N: Previous search match
 +
*ESCu: Turn off match highlighting (see -g option)
 +
*v: Edit content mode (vi)
 +
*h: Help. q to quit
 +
*q: Quit

Latest revision as of 17:17, 23 May 2018

Useful Linux Commands

We use Suse linux (SLES) as one of the main OSs for our products.

You can use man [command] to get information about a command, but that is more programmer oriented. You are generally better off going to a search engine and searching for [command] examples.

One of the great powers of Linux is being able to pipe | or redirect outputs from one command to another to do things.

Another thing is TAB complete is a useful tool, once you have a few characters in place you can press tab to complete the command or directory. Pressing tab twice quickly will show all other entries available.

You can also use these commands to create bash scripts. Save it as a script file "filename.sh" and give it execute rights "chmod +x filename.sh".

Superuser mode

sudo [command]
su -

Starting and Stopping Tomcat/mysql/apache

SLES11

rcretain-tomcat7 start|stop|restart|status
rcmysql start|stop|restart|status
rcapache2 start|stop|restart|status

SLES12

systemctl start|stop|restart|status retain-tomcat7.service
systemctl start|stop|restart|status mysql.service
systemctl start|stop|restart|status apache2.service

Contents

[edit] System

[edit] Increasing the number of open files limits

By default SLES allows 4096 open files for a non-root user. This may be too small.

On linux in general you will have two places that you will need to look at in in increasing or decreasing the amount of open files that can be used.

1. First is the system wide limit. On SLES and most other Linux versions this is done in:

/etc/sysctl.conf
fs.file-max = desirednofiles

Then run:

sysctl -p

The sysctl -p reads the sysctl.conf file so you don't need to reboot for it to take effect. This doesn't work for all settings in sysctl, but it does work for maximim files.

2. The second limit setting is on a per user basis. This is important, because you may have a system wide maximum set quite high, but if your user is not listed here, it will have very small limit set of 4096.

To set this on SLES, you'll do the following:

(NOTE: this may be different on other linux distros)

First, edit the file:

/etc/security/limits.conf 

To set the number of limits for the tomcat user do the following:

tomcat	 hard    nofile 	 500000
tomcat	 soft	 nofile	  500000

Save the file, and reboot the server.

To verify the limits are correct, you can normally do this, but for tomcat in your instance I could not find a way to verify:

ulimit -Hn    (show hard limit, while logged in as whatever user you want to list the limit for)
ulimit -Sn    (show soft limit, while logged in as whatever user you want to list the limit for)

3. Last of all, for the individual user limits, you need to make sure that /etc/pam.d/common-session has the following line:

session   required   pam_limits.so

[edit] Disk Commands

[edit] df Disk Free

Returns a quick overview of what disks are mounted and how full they are in human readable formatting.

df -h

Sometimes a disk becomes full even though there appears to be plenty of room left. You may be out of inodes.

df -i

To determine the filesystem type of the volumes.

df -T

[edit] mount Mount a file system

Mount a file system or device. You can also type mount by itself to show current mounts on the system. Before making the mount, make sure you have a directory on the Linux box to mount the filesystem to. Usually mounts go under the /mnt directory.

Create a mount point

mkdir /mnt/whatever

Once you have the directory set up, you can now mount the filesystem or share.

Linux mounts use nfs usually:

mount -v -t nfs 10.1.1.20:/exportdir /mnt/whatever 

Netware mounts use npc usually:

ncpmount -S [server] -A [IP address] -U [fully distinguished name] -V /vol1 /mnt -o tcp

NSS mount

ncpmount -A 10.1.6.152 -S <serverName> -U <eDirectory FQDN> -H nfs -V <NSS volume name> /mnt/temp

Example:

ncpmount -S school -A 192.168.100.1 -u admin.wwws  -V vol1 /mnt/nwserver -o tcp

Windows mounts can use cifs or samba:

mount -t cifs //ntserver/download -o username=admin,password=password /mnt/whatever
mount -t smbfs -o username=admin,password=password //ntserver/download /mnt/ntserver

Note: Reload comes with some nice scripts that Tay created for setting up cifs and ncp mounts. They are found under /opt/beginfinite/reload/setup. You just enter the setup information into the corresponding conf file and run the script.

cifsmnt.conf:

    1. Author: Tay Kratzer taykratzer@taykratzer.com ##
    2. All values must be kept within double quotes. ##

CIFS_USERNAME="administrator" CIFS_PASSWORD="windoze" CIFS_SHARE="share1" CIFS_SERVERIP="137.65.55.210" CIFS_RETRY_COUNT="10" CIFS_RETRY_SECONDS="30" LINUX_MOUNT_POINT="/mnt/winserver"

ncpmnt.conf:

    1. Author: Tay Kratzer taykratzer@taykratzer.com ##
    2. All values must be kept within double quotes. ##

NCP_LOGIN_NAME="admin.acme" NCP_LOGIN_PASSWORD="novell" NCP_VOL="sys" NCPVOL_SERVERIP="137.65.55.210" NCPVOL_SERVERNAME="wwwfs1" NCPVOL_MAP_RETRY_COUNT="10" NCPVOL_MAP_RETRY_SECONDS="30" LINUX_MOUNT_POINT="/mnt/nwserver"

Once you've set up the conf file, run the script from the command line.

[edit] umount Unmount filesystem

umount – Unmount a device or mounted filesystem.

umount /mnt/whatever

Lazy unmount that allows the server to clear resources in the background once they are no longer busy

umount -l /mnt/temp

[edit] Check NFS version

Determine nfs version

nfsstat -s (-s for server, -c for client)

[edit] Directory Commands

[edit] cd Change Directory

Change directory. Tab complete can help traverse the tree.

cd [destination directory]

Change to root directory

cd /

go up one level

cd ..
..

go up two levels

cd ../..
...

[edit] du Directory details

Returns an estimate of file space usage, in human readable format (k,M,G). Warning: May take a long time.

du -h

To get a human readable(h) summary(s) of a directory below the current directory.

du -sh *

Returns a total size of the directories under where this command was run and sorts by size.

du -hsx * | sort -rh | head -10

[edit] md Create a directory

Creates a directory

md [directory name]
mkdir [directory name]

[edit] cp -R Copy a directory

Copy a directory recursively "R"

cp -R [source] [destination]

[edit] rm -r Remove a directory

Removes a directory and its contents. Use -f if you need to force the issue. Warning: irreversible, fast and dangerous if done in the wrong place with wrong switches.[1]

rm -r [directory]
rm -rf [directory]

[edit] l Directory List

Return a list of files in a directory. This always works (shows file size in bytes)

ls -s

This is a SLES alias of the above*See Note below

l

The following command is an alias used in both SLES and Ubuntu as a shortcut for ls -l

ll

Display file size in human-readable values "-h" (K,M,G)

l -h

Sorted by size "S", ascending "r", human-readable "h"

l -Srh

Sorted by time "t", ascending "r", human-readable "h"

l -trh

Show hidden files "a", long list format "l", human-readable "h"

l -alh

Sorted by reverse chonological order

l -qaltr

Sorted by reverse order, human readable

l -lhr
*Note: l is not recognized as an alias in Ubuntu, this is a SLES specific shortcut.  ls and ll are generally universal. handy man page if you'd like to know more: http://man7.org/linux/man-pages/man1/ls.1.html

[edit] lsof List Open Files

List all open files

lsof

List files that are listening on port 5555

lsof -i tcp:5555

lsof - “List Open Files” Options I’ve found useful Include ports in use and what process is using them to how many files a process is using.

Example to find if a port is being used and what process is using it (including pid):

testserver:~ # lsof -i {tcp/udp}:{port}

What it would look like in use:

testserver:~ # lsof -i tcp:25
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
gwvsmtp 3090 root    8u  IPv4   9498      0t0  TCP *:smtp (LISTEN)

If you want to see all the TCP/UDP info just use:

testserver:~ # lsof -i
COMMAND     PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
postgres   1652 postgres    3u  IPv4    6698      0t0  TCP *:postgresql (LISTEN)
..
..

Example of number of files open by a process (must know the PID before use):

testserver:~ # lsof -p {pid of process} | wc -l"

What it would look like used:

testserver:~ # lsof -p 30976 |wc -l
1403

[edit] find directory

Find a directory by name from the root

find / -type d -name [folderName]

[edit] chmod Change Permissions

Permissions are a big deal in Linux [2] not so much in Windows.

Add the execute permission to all shell scripts in the current directory

chmod +x *.sh
chmod -R +x *.sh

Add read and write permissions to User and Group but only read to Other recursively "R" in the destination directory

chmod -R 664 /[destination]

Add Execute, read, and write permissions to User and Group but only read to Other recursively "R" in the destination directory

chmod -R 774 /[destination]

Add all the permissions

chmod -R 777 /[destination]

[edit] chown Change Ownership

Ownership of a directory can make a big difference in how Retain works

chown user:group directory/

Change the ownership recursively "R" to user tomcat and group tomcat of the logs directory in the current directory

chown -R tomcat:tomcat logs/

[edit] File Commands

[edit] cat Concatenate

Show the contents of a file

cat "filename"

Pipe through more to display a screen full of text at a time (space for next page, enter for next line, ctrl-c to break out)

cat "filename" | more

Pipe through less to display file in less.

cat "filename" | less

[edit] diff Find difference between files and directories

Compare two files

diff file1.txt file2.txt

Show the difference between two directories and the files in each [3]

diff ~dir1 ~dir2

Show only the differences between directories by adding the q option. Add the r option to recurse down the directory structure

diff -qr ~dir1 ~dir2 | sort

[edit] Find a file, and other uses for the Find command

Find a file from the root of the file system (aka looks everywhere for it) Warning: may take a long time. [4]

find / -name "fileName"

Find all files with the string "log" as part of the filename.

find . | grep log

Find and recursively unzip all items in a directory structure called zippedDir to the current directory.

find /zippedDir/-name "*.zip" -exec unzip {} \;

Find files in current directory older than 7 days and delete them.

find . -mtime +7 -exec rm {} \;

Find any file off the root and beyond that is larger than 20M:

find / -type f -size +20M -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'

Find 10 largest files starting at /(root) find / -printf '%s %p\n'| sort -nr | head -10

Find the number "wc" lines "l" of files "-type f" in a directory structure:

find [directory]/ -type f | wc -l

Change all the files named “*.msgstorage” to *.msg. I.E. file.msgstorage to file.msg in the current directory and children directories

find . -name "*.msgstorage" -exec rename .msgstorage .msg {} +

Report all known instances of a command. A quick way to find out if something is installed.

whereis [commandname]

[edit] cp Copy file

cp origin /destination/file

To copy particular files recursively

cp -r *.txt /destination

To copy to the current directory

cp /software/origin.file .

[edit] scp Secure File Copy

To secure copy a file from a remote location

scp [username]@[source IP address]:/[source directory]/[source file] /[destination directory]

To secure copy a file to a remote location

scp [source] [username]@[destination IP address]:/[destination]

[edit] rsync Remore sync

Sync a file or directory between locations, recurse "r" through subdirectories, retain "a" permissions, ownership and timestamps, verbose "v" logging to screen, show progress "P"

rsync -ravP [source] [destination]

[edit] mv Move file

Moves file to the destination directory in verbose "v" mode.

mv -v "file" "destination"

[edit] rm Remove or delete a file

Removes a particular file

rm "file"

Remove all files older than 7 days

find . -mtime +7 -exec rm {} \;

[edit] chmod Change Permissions

Permissions are a big deal in Linux [5] not so much in Windows. Add execute "x" rights to all levels on all shell scripts in the current directory

chmod +x *.sh

[edit] ln Symbolic link

Make symbolic links between files. This is useful if you need to change the log directory or repair a symbolic link that was removed.

ln -s [path to new directory] ./retain-tomcat7

To remove a symbolic link

rm linkname (without trailing /)

Get full link path

readlink -f <symlink directory or file>

[edit] Change UserID

List the users to get their userids

cat /etc/passwd
id [username]
usermod -u [desired new userid] [username]

[edit] Network

[edit] wget Get File from website

Download the Latest Version of Retain

wget "http://download.gwava.com/download.php?product=Retain&version=current"

SLES 12 tip: To give a file downloaded through wget an actual name instead of it giving it the URL name use the -O switch:

wget “http://url/file.txt” -O name.you.want.to.give.file.on.disk.txt

[edit] ifconfig Find IP Address

Find the IP address of the server. Use this command to find the IP address(es) and MAC address(es) the system uses. eth0 is the first NIC. If the system has multiple NICs, they are named, eth0, eth1, and so on. lo is loopback.

ifconfig

[edit] host Lookup DNS records

look up mx records

host -t MX [domain.com]

Determine hosts

cat /etc/resolv.conf 

[edit] ping Contact Server

Ping to see if a server is alive. Ctrl-c to stop.

ping [ip address]

[edit] DNS commands

DNS

nslookup
server
dig [servername or ipaddress]

Clear DNS Cache by stopping and starting the service

rcnscd stop 
rcnscd start

[edit] traceroute Find route between servers

Trace the route to a server

traceroute [domain.com]

[edit] hostname Name of Computer

Show the system name

hostname

[edit] ssh Secure connection

Secure connect to another system, exit to leave ssh shell

ssh [hostname or ip address]

[edit] telnet Connect between servers

Useful for testing connections. You can send a test email with it:

telnet [IP address or DNS hostname] [port]
ehlo [ENTER]
mail from:  retain@[your domain name]  (note: the "from" can actually be spoofed - it really can contain any text of user@domain.com)[ENTER]
rcpt to: [yours or a user's email address][ENTER]
data[ENTER]
subject:  test email from telnet on Retain server[ENTER]
This is a test[ENTER]
.[ENTER]   (you are literally typing a "period" here and pressing [ENTER])
quit[ENTER]

[edit] netstat Network activity monitor

A useful tool for checking your network configuration and activity.

netstat -lnp -A inet

To get port information

netstat -A inet -n -p |grep [PID]

[edit] Process Commands

[edit] free Memory usage

Display memory usage

free -m

[edit] top System resources

Display an overview of the system resources can be used to find a process

top

I/O statistics

iotop -o

[edit] vmstat Virutal Memory Statistics

Report virtual memory statistics: processes, memory, paging, block IO, traps, and cpu activity.

vmstat

[edit] swap space

See this article for determining swap space [6]

[edit] chkconfig Check runlevel

Check runlevel of a process

chkconfig [process name]

[edit] ps aux Find a process

To find a running process you know the name of

ps aux | grep [process name]

[edit] kill End a process

see find a process or top You have to find a runaway process with top or ps

kill [process ID]

It the process us hung you may have to be more forceful

kill -9 [process ID]

To kill all processes associated with a particualr name

killall -15 [processname]

[edit] w Who is logged in

Returns a list of logged in users if the TTY column shows "pts/3" that shows us that use is remotely logged in.

who
w

[edit] fstab File system information

The fstab file will also contain information about any mounted filesystems as well

cat /etc/fstab

[edit] Find Linux Version

To find the SLES version of Linux that is installed use this command:

cat /etc/issue
"uname -r" (kernal build)
cat /etc/*-release (all version info)

[edit] Utilities

[edit] CPU information

Provides detailed CPU information

lscpu

[edit] file system information

Provides detailed information about the filesystem df has a switch for that, and it is nicer when it is human readable

df -Th

Shows name, volume, file system type, and mount point. Also shows what volume is on what disk (pretty)

lsblk -f 

Shows volume, uuid and file system type

blkid

[edit] history Command history

Get a history of commands

history

To run a past command

![+number of command to run from history]

To run a past command by name

![Ctrl-r][start typing desired command]

[edit] Checking disk performance

use the dd command[7]

server throughput (write speed) write 1 GB to disk (this should be above 50MB/s)

dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync

measure server latency (this should be above 1 MB/s)

dd if=/dev/zero of=/tmp/test2.img bs=512 count=1000 oflag=dsync


[edit] tar Create archives

Create an uncompressed tape archive of a bunch of files

tar -cvf [dest file name].tar [source directory] 

Extract a tar

tar -xvf [filename] 

[edit] zip/gzip Compress files

Zip

zip [dest file name] [source files or directory] 

Unzip

unzip [file].zip -d /[directory]

Create a gzipped tar file

tar -czvf [dest file name] [source directory] 

Extract a gziped tar

tar -xvzf [filename] 

Extract gzip

gzip -dv [file name]

[edit] clear Clear Screen

Clear Screen

clear

[edit] Screen command

Keeps a terminal session open even if the shell gets closed. Some tutorials [8][9]

  • To start a session:
    • In a terminal windows, type “screen” and press ENTER.
  • Hit CTRL-A to send a command to the “screen” session.
  • New window: CTRL-A c
  • Move to next window: CTRL-A n
  • Move to previous window: CTRL-A p
  • To restore a session (if the terminal window gets closed):
    • Login to a new terminal session.
    • Type: screen -r
  • To stop a session, simply type “Exit” in a terminal window.

[edit] crontab Schedule Tasks

crontab – Schedule a command to run at a later time.

Each line in the cron (cron is the daemon) table follows the following format: 7 fields left to right. Field Meaning 1 Minute (0-59) 2 Hour (2-24) 3 Day of month (1-31) 4 Month (1-12, Jan, Feb, ...) 5 Day of week (0-6) 0=Sunday, 1=Monday ... or Sun, Mon, Tue, Wed, Thur, Fri 6 User that the command will run as 7 Command to execute

So, if you want to have Netcleanse restart the ntp-client to reset the time every hour, then you'd use this command:

This will load the crontab editor. Add the entry below, save the change and exit the editor.

crontab -e

Restarts ntp-client every minute

0 * * * * root /etc/init.d/ntp-client restart

Runs the script at the top of every hour

00 */1 * * * /root/Desktop/gopostal/gopostalfullauto.sh

[edit] date Date and time

This command can be used to display the current time on the server or adjust the time.

date

[edit] rcmysql MySQL control commands

To control MySQL services you can use these commands:

rcmysql [start|stop|restart|status]

To determine the MySQL version, you can use one of these commands:

mysql --version
mysqlshow -V

[edit] rcapache2 Apache control commands

To control apache services you can use these commands:

rcapache2 [start|stop|restart|status]

[edit] rcretain-tomcat7 Tomcat control commands

To control tomcat services you can use these commands:

rcretain-tomcat7 [start|stop|restart|status]

[edit] rpm Package Installer

Package installer. There are numerous useful flags that can be used with this command. For those flags, look here: http://www.novell.com/coolsolutions/tip/19918.html Most commonly, however, you'll just use the commands to install, upgrade and uninstall.

rpm -ivh [filename].rpm

To uninstall

rpm -e [filename].rpm

[edit] shutdown Shutdown and reboot

Reboot the server

reboot
shutdown -r now (same as reboot)
init 6 (not preferred)
reboot -f (Last resort reboot method. The only time you'd want to use this option is if something is wrong with the init daemon.)

Shutdown

shutdown -h now
init 0 (last resort)

[edit] telnet

Send a test message via telnet

telnet x.x.x.x 25
ehlo<enter>
mail from: <test@test.com><enter>
rcpt to:<validuser@yourdomain.com><enter>
data<enter>
subject: test<enter>
testing <enter>
.<enter>
quit<enter>

and you should see a result similar to this:

220 g6postgres109.mydomain.com GWAVA Proxy Copyright (c) 2011 GWAVA, Inc. All rights reserved. Ready
ehlo test.com
250-g6postgres109.mydomain.com
250-AUTH LOGIN
250-8BITMIME
250 NO-SOLICITING
mail from:<test@test.com>
250 OK
rcpt to:<user4@mydomain.com>
250 Ok
data
354 Start mail input; end with <CRLF>.<CRLF>
subject: test
testing
.
250 Ok

[edit] watch process or command

Watch will repeat the command every 2 seconds for monitoring purposes

watch "<command>"
watch "ls -al"
watch "ps aux | grep dbcopy"

Example: Command: telnet Example of watching DBCOPY, which Reload launches and sets up various ports depending on what it is doing (5001=user db copy; 5002=msg db copy, etc.)

telnet 10.1.5.101 5001

While that telnet session is running, there are several commands that can be issued:

  • rff - request for file
  • rfc - request for the data
  • rfs - request for shutdown (will shutdown the computer)
  • rft - request for file (real time) - hit CTRL-] to break out of it.
  • frl - external library


If you wish to change the iteration time from 2 second to 1 second up to 4200 seconds use the -n switch (you can either have a space or no space between the -n and the seconds you wish to iterate)

watch -n30 "ls -al"

Advanced: The following will show the output to the command line and a log file:

watch -t "(date '+TIME:%H:%M:%S' ; du -sh /file/path/you/wish/to/watch) | tee -a size.log"

Notes: In the above command you could add the -n switch before or after the -t. The file path on the du command is variable to what you want to watch, and the "size.log" can also be a file path. For example you could put /var/log/retain-tomcat7/mylog.log. The way it is in the above example it will write the log in the path that you run the command.

[edit] Text Editing

[edit] vi Text Editor

vi – Text editor for Linux. There are a variety of commands you can use in vi, here are some of the most useful:

To open a file:

vi [filename]
  • i: Insert text
  • ESC: Exit mode, for example, exit the insert text mode
  • /: Perform a search (n, repeats search; N, search backwards)
  • dd: Deletes a line
  • yy: Copies current line
  • yw: Copies current word
  • u: Undo last change
  • p": Pastes whatever was copied after the cursor position
    wq: Writes changes and exits vi
    q!: Quits without saving changes

For more details on using vi, look here: [10] It's better then edlin.

[edit] less File viewer program

Less lets you view the contents of a text file by screenfuls.

less [options] [filename]

Options:

  • -g: Highlights just the current match of any searched string.
  • -I: Case-insensitive searches.
  • -M: Shows more detailed prompt, including file position.
  • -N: Shows line numbers (useful for source code viewing).
  • -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
  • -?: Shows help.
  • +F: Follow mode for log.

Once in less there are a number of commands that you can use:

  • spacebar or page down: for next page
  • page up or b: for previous page
  • enter or j: for next line
  • k: for previous line
  • Shift-f: for follow mode. ctrl-c to abort follow mode.
  • g or <: Return to first line
  • G or >: Go to last line
  • /[text]: Forward search for [text]
  • ?[text]: Backwards search for [text]
  • n: Next search match
  • N: Previous search match
  • ESCu: Turn off match highlighting (see -g option)
  • v: Edit content mode (vi)
  • h: Help. q to quit
  • q: Quit
Personal tools
Namespaces

Variants
Actions
Home
Exchange
GroupWise
JAVA
Linux
MTK
Retain
GW Monitoring and Reporting (Redline)
GW Disaster Recovery (Reload)
GW Forensics (Reveal)
GWAVA
Secure Messaging Gateway
GW Mailbox Management (Vertigo)
Windows
Other
User Experience
Toolbox
Languages
Toolbox