<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux Commands Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/linux-commands/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/linux-commands/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 27 Feb 2021 09:52:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>Linux Commands for Administrator &#124; Linux Admin Commands Reference</title>
		<link>https://www.scmgalaxy.com/tutorials/linux-commands-for-administrator/</link>
					<comments>https://www.scmgalaxy.com/tutorials/linux-commands-for-administrator/#respond</comments>
		
		<dc:creator><![CDATA[scmgalaxy K]]></dc:creator>
		<pubDate>Mon, 21 Jul 2014 00:00:00 +0000</pubDate>
				<category><![CDATA[Unix - Linux]]></category>
		<category><![CDATA[Admin Linux Commands]]></category>
		<category><![CDATA[Administrator]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux Admin Commands Reference]]></category>
		<category><![CDATA[Linux Commands]]></category>
		<category><![CDATA[Linux Commands for Administrators]]></category>
		<category><![CDATA[Linux Commands for Administrators Guide]]></category>
		<category><![CDATA[Linux Commands for Administrators Reference]]></category>
		<category><![CDATA[Linux Commands for Administrators Tutorials]]></category>
		<category><![CDATA[Linux Commands Guide]]></category>
		<category><![CDATA[Linux Commands Reference]]></category>
		<category><![CDATA[Linux Commands Tutorials]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/2014/07/21/linux-commands-for-administrator/</guid>

					<description><![CDATA[<p>su: Acquiring Superuser Status # su  :- Acquire  Superuser after entering password but home directory does not change # su [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/linux-commands-for-administrator/">Linux Commands for Administrator | Linux Admin Commands Reference</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-3667 aligncenter" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2014/07/linux-commands-administrato.png" alt="linux-commands-administrators" width="600" height="400" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2014/07/linux-commands-administrato.png 600w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2014/07/linux-commands-administrato-300x200.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p><strong>su: Acquiring Superuser Status</strong><br />
# su  :- Acquire  Superuser after entering password but home directory does not change<br />
# su – l :– Acquire Superuser access after password but home  directory change to ROOT<br />
# su  &#8211; henry : &#8211; To  Login and Recreate a user environment<br />
# sudo -s root -c &#8220;/bin/bash -l&#8221;</p>
<p><strong>passwd – Changing any Password</strong><br />
# passwd henry<br />
stat &lt;fileName&gt;</p>
<p><strong>ulimit – Setting Limits on file size</strong><br />
ulimit command impost a restriction on the maximum size of a file that a user is permitted to create<br />
# ulimit 20971510                             This is often placed in /etc/profile. Measured in 512 byte blocks</p>
<p><strong>umask – Please refer user manual</strong></p>
<p><strong>Source</strong><br />
The source command in shell is used to execute commands from a file in the current shell. This is useful to load function or variables stored in another file.<br />
# source filename<br />
# source /path/to/file</p>
<p><strong>locate</strong></p>
<pre><strong>To locate any files in system. This works based on </strong>updatedb.</pre>
<pre># locate</pre>
<pre># updatedb     Run as a root.File location is /var/lib/mlocate/mlocate.db</pre>
<p><strong>which </strong><br />
shows the full path of (shell) commands</p>
<p><strong>od</strong><br />
od command dumps a file in octal, decimal, and other formats.</p>
<pre># od -c special-chars.txt</pre>
<p># od -bc special-chars.txt</p>
<p><strong>chkconfig</strong><br />
chkconfig command is used to setup, view, or change services that are configured to start automatically during the system startup.</p>
<p>The –list option displays all the services with the current startup configuration status.<br />
# chkconfig &#8211;list<br />
To view only the services that are configured to be started during system startup, do the following. Please note that this assumes that your system startup level is 3<br />
# chkconfig &#8211;list | grep 3:on<br />
To display the current settings for a selected service only, use chkconfig &#8211;list followed by the name of the service:<br />
# chkconfig &#8211;list service_name</p>
<p>To enable a service in runlevels 2, 3, 4, and 5, type the following at a shell prompt as root.<br />
# chkconfig service_name on<br />
To disable a service in runlevels 2, 3, 4, and 5, type the following at a shell prompt as root.<br />
# chkconfig service_name off</p>
<p># chkconfig network &#8211;level 3 &amp;&amp; echo &#8220;Network service is configured for level 3&#8221;<br />
# chkconfig network &#8211;level 1 &amp;&amp; echo &#8220;Network service is configured for level 1&#8221;</p>
<p>To view the startup configuration of a particular service, grep the output of ‘chkconfig –list’ for that service.<br />
# chkconfig &#8211;list | grep network</p>
<p>Add a new Service to the Startup<br />
# chkconfig &#8211;add iptables</p>
<p>To remove it from the startup list, use the –del option as shown below.<br />
# chkconfig &#8211;del ip6tables</p>
<p><strong>How to install services?</strong></p>
<pre><strong>Step 1. Copy the script into </strong>/etc/init.d/ such as /etc/init.d/httpd</pre>
<pre>Step 2. chkconfig --add httpd</pre>
<p>http://bitnami.org/article/how-to-install-services-on-linux</p>
<p><strong>service</strong><br />
# service network restart<br />
OR<br />
# /etc/init.d/network restart</p>
<p>To start Linux network service:<br />
# service network start</p>
<p>To stop Linux network service:<br />
# service network stop</p>
<p><strong>date – Setting the system Date</strong><br />
# date MMDDhhmm</p>
<p><strong>groupadd</strong><br />
# groupadd –g 241 dba               The command place entry in /etc/group which can also insert manually(dba:x:241). 241 is GID of dba</p>
<p><strong>useradd</strong><br />
# useradd –u 210 –g dba –c “The RDBMS” –d /home/oracle –s /bin/bash –m username</p>
<p><strong>usermod</strong><br />
# usermod –s /bin/csh username</p>
<p><strong>userdel</strong><br />
# userdel username</p>
<p><strong>shutdown</strong><br />
# shutdown 17:30                         Shutdown at 17:30<br />
# shutdown –r now                     Shutdown immediately and reboot<br />
# shutown –r 17:30                      Shutdown immediately and reboot at 17:30<br />
# shutown –h now                       Shutdown immediately and halt<br />
# shutown –h 17:30                     Shutdown at 17:30<br />
# shutdown –c                               Cancel the shutdown<br />
Reboot / Poweroff / halt</p>
<p><strong>df</strong><br />
The df (disk free) command lets you see if file systems are full.</p>
<ul>
<li>To see how much free space is in all file systems (including mounted ones), use df</li>
<li>To see how much free space is in all file systems with names containing &#8220;dev&#8221;, use df | grep dev</li>
<li>To see how much free space is in your home file system, use df /home</li>
<li>To see how much free space is in the file system &#8220;tmp&#8221;, use df /tmp</li>
<li>To see if there is enough free space on the machine, check the output from the following</li>
</ul>
<p># df /usr,<br />
# df /var<br />
# df -k /tmp /home                                          -k Reports in units of KB<br />
<strong># </strong>df –h / /usr                                                       -h reports in MB, GB</p>
<p><strong>du -Disk usage</strong><br />
# du  /home/sales/tml<br />
# du –s /home/*                                               -s options for summary disk usage information for tml directory<br />
# du –sh /home                                                 -h options for reports in MB , GB<br />
# find /home –size +1024 –print                                     Files above 1MB<br />
# find /home –size +1024 –size -4096 – print             Files above 1Mb and below 4MB</p>
<h3><a title="mount / unmount" href="scm/operating-systems/unix-linux/mount-and-unmount-filesystem-partition-in-linux.html" target="_blank" rel="noopener">mount / unmount</a></h3>
<p><strong>Using file for incremental Backup</strong><br />
# tar –cvf /dev/rct0 `find /home –type f –newer .last_time –print`<br />
# touch .last_time<br />
# tar –cvf /dev/rct0 /home &gt; homelist `date “+%d%b%y”`</p>
<h3><a href="scm/operating-systems/unix-linux/20-xargs-command-examples-in-linux-unix.html" target="_blank" rel="noopener">xrags</a></h3>
<h3><a href="http://danielmiessler.com/blog/linux-xargs-vs-exec/">xargs vs. exec {}</a></h3>
<p><strong>Remote machine Login: telnet, rlogin</strong><br />
<strong>telnet</strong><br />
<strong>rlogin</strong></p>
<p><strong>Secure Login with password: ssh </strong><br />
<strong>ssh</strong></p>
<p><strong>Remote login without Password: rsh</strong><br />
<strong>rsh</strong></p>
<p><strong>File Transfer: ftp, rcp, scp</strong><br />
<strong>rcp</strong></p>
<p><strong>scp</strong></p>
<p><strong>ftp</strong><br />
ftp rajesh-servers &#8211; How to Login<br />
Directory Commands:<br />
# cd [directory] Changes to the specified directory on the remote system.<br />
# dir Displays a long listing of files on the remote system.<br />
# ls Displays a short listing of the files on the remote system.<br />
# lcd Changes the working directory on the local system.<br />
# pwd Displays the working directory on the remote system.<br />
File Transfer Commands:<br />
# get [filename] Downloads a single file from the remote system.<br />
# put [filename] Uploads a single file to the remote system.<br />
# mget [file&#8230;] Downloads multiple files from the remote system.<br />
# mput [file&#8230;] Uploads multiple files to the remote system.</p>
<p><strong>Generic troubleshooting tips</strong></p>
<ul>
<li>Use tail –f to watch log file in real time, advantage is simple you can spot error or warning message in real time.<br />
<strong>tail –f /path/to/log/file</strong><strong><br />
Example(s):<br />
<strong># tail –f /var/log/maillog</strong></strong></li>
<li>Use telnet command to see if you get response or not. Sometime you will also see some informative message:<br />
<strong>telnet ip port</strong></li>
</ul>
<p>Example(s):<br />
<strong># telnet localhost 53</strong><br />
<strong># telnet localhost 25</strong></p>
<ul>
<li>Make sure you can see PID of your service.<br />
<strong>pidof service-name</strong><strong><br />
<strong>cat /var/run/service.pid</strong></strong><strong><br />
Example(s):<br />
<strong># pidof sshd</strong><br />
<strong># cat /var/run/sshd.pid</strong></strong></li>
<li>You need to make sure that your DNS server or third party DNS server (ISP) is accessible. This is an important step, as many network services depend upon DNS; especially sendmail/postfix or Squid etc for example. Run dig or nslookup. No timeout should occurred.<br />
<strong><br />
<strong># dig your-domain.com</strong><br />
<strong># nslookup gw.isp.com</strong><br />
<strong># more /etc/resolv.conf</strong></strong></li>
</ul>
<p><strong>Performance /  Memory / CPU / Process check</strong><br />
<strong>ps</strong> – Read user manual</p>
<p><strong>w username</strong> &#8211;  Find Out Who Is Logged on And What They Are Doing. w command displays information about the users currently on the machine, and their processes.</p>
<p><strong>top</strong><br />
The top program provides a dynamic real-time view of a running system i.e. actual process activity. By default, it displays the most CPU-intensive tasks running on the server and updates the list every five seconds.</p>
<p><strong>uptime</strong><br />
tell How Long The System Has Been Running</p>
<p><strong>free &#8211; Memory Usage</strong><br />
The command free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.<br />
# free –m                                                            Display free memory size in MB<br />
# free -t –m                                                        Displays a line containing the totals memory in MB</p>
<h3><a href="scm/operating-systems/unix-linux/20-vmstat-command-examples-in-linux-unix.html" target="_blank" rel="noopener">vmstat<br />
</a><br />
<a href="scm/operating-systems/unix-linux/linux-performance-monitoring-using-iostat-mpstat-and-vmstat.html" target="_blank" rel="noopener">Linux Performance Monitoring using iostat, mpstat and vmstat</a></h3>
<h3><a href="scm/operating-systems/unix-linux/20-iostat-command-examples-in-linux-unix.html" target="_blank" rel="noopener">iostat</a></h3>
<h3><a href="scm/operating-systems/unix-linux/20-pmap-commands-examples-in-linux-unix.html" target="_blank" rel="noopener">pmap </a><br />
<strong><br />
</strong><a href="scm/operating-systems/unix-linux/20-mpstat-command-examples-in-linux-unix.html" target="_blank" rel="noopener">mpstat </a></h3>
<p><strong># strace &amp; truss &#8211; Debug the Execution of a Program in Linux</strong><br />
Trace the Execution of an Executable<br />
# strace ls</p>
<p>Save the Trace Execution to a File Using Option -o<br />
strace -o output.txt ls</p>
<p>Execute Strace on a Running Linux Process Using Option -p<br />
# ps -C firefox-bin To get the process id<br />
# sudo strace -p 1725 -o firefox_trace.txt</p>
<p>Print Relative Time for System Calls Using Option -r<br />
# strace -r ls</p>
<p><strong>Networking troubleshooting tips</strong></p>
<p><span style="text-decoration: underline;">Hostname verification or setup tools</span></p>
<ul>
<li>hostname : To get hostname of server.</li>
<li>hostname –s : To get FQDN hostname of server</li>
<li>more /etc/sysconfig/network : To setup hostname and networking can enable or disabled.</li>
<li>dnsdomainname : List or setup domainname.</li>
<li>more /etc/hosts : Make sure at least localhost entry do exist.</li>
</ul>
<p><span style="text-decoration: underline;">Ethernet configuration tools</span></p>
<p><strong>service network reload|restart|stop|start :</strong> To reload (after changed made in ip config file)|restart|stop|start network interface with all properties.</p>
<p><strong>route</strong><br />
The route command allows you to add static routes to the routing tabling.</p>
<p><strong>traceroute (tracert in Windows)</strong><br />
Traceroute displays the routers that are passed through to reach the destination.</p>
<p><strong>dmesg</strong><br />
When the system boots up, it prints number of messages on the screen that displays information about the hardware devices that the kernel detects during boot process.<br />
These messages are available in kernel ring buffer and whenever the new message comes the old message gets overwritten. You could see all those messages after the system bootup using the dmesg command.</p>
<pre># dmesg | more</pre>
<pre># dmesg | grep Memory</pre>
<pre># dmesg  | grep eth</pre>
<pre></pre>
<p><strong>ifconfig</strong><br />
The ifconfig command is used to display the local interface configuration (winipcfg for Windows) and to modify the configuration.<br />
ifconfig eth0 up|down : To enable|disable network interface</p>
<p><strong>netstat</strong><br />
The network status command netstat displays status information about the network interfaces on the host machine. Netstat command displays the network related information such as network connections, routing tables, interface statistics.<br />
-a                Show both listening and non-listening sockets<br />
-n                prints the numeric forms of IP address</p>
<p># netstat -ain                                  Local interface status<br />
# netstat -rn                                    Routing table information<br />
# netstat –an                                  Display Active Internet Connections and domain sockets using netstat<br />
# netstat -tap                                 Display Active Connections with Process ID and Program Name<br />
# netstat –-route                          Display Routing Table<br />
# netstat &#8211;statistics &#8211;raw         Display RAW network statistics<br />
# netstat &#8211;tcp &#8211;numeric           List of TCP connection to and from the machine.<br />
netstat -tuplin                                UNIX</p>
<p><strong>iptables </strong></p>
<p>To know which ports are running in the machine.<br />
<strong>ping</strong><br />
The ping command allows you to determine that the:</p>
<ul>
<li>TCP/IP stack is configured properly</li>
<li>Network interface card is configured properly</li>
<li>Default gateway and subnet mask is configured properly</li>
<li>Domain name services is configured properly.</li>
</ul>
<p><strong># ping ipaddress</strong> to check if the ip address in connected with network and if host is alive or dead<br />
<strong># ping 127.0.0.1/localhost</strong> &#8211; to check TCP/IP services is running properly or not. Checks that your TCP/IP stack is working properly up to the NIC. If this fails, check to see if you have TCP/IP services loaded.<br />
<strong># ping &#8220;IP address of default gateway&#8221;</strong> &#8211; Checks that the NIC is working on the local subnet by pinging the local side of the default gateway which is a router. If this fails, check that TCP/IP is bound to the NIC. Then check that the NIC&#8217;s IRQ, and base address are set properly both on the card itself and in the operating system&#8217;s interface configuration.<br />
<strong># ping &#8220;domain name&#8221;</strong> if DNS name is correctly configured. If it fails, check that the DNS server&#8217;s IP address is entered in properly in the TCP/IP configuration.</p>
<pre><strong>arp</strong></pre>
<pre><strong>address resolution protocol</strong></pre>
<p><strong># arp </strong>  &#8211; To see the IP to MAC address translation table<br />
<strong># arp -a</strong>  -Use this command to see the IP to MAC address translation table if you are having problems connecting to other network hosts. It is a dynamic cache which updates every 120 seconds.</p>
<p># more /etc/modules.conf : To see your network card configuration alias for eth0 exists or not.<br />
# lsmod : To list loaded modules (read as drivers), here you need to see that eth0 module is loaded or not, if not loaded then use insmod to insert (load) driver.<br />
# dhclient : Dynamic Host Configuration Protocol Client, run this if your Ethernet card is not getting ip from DHCP box on startup; this command does by default shows useful information.</p>
<p><strong>To see if service blocked because of access control</strong><br />
# iptables –n –L : To list all iptable rules; useful to see if firewall blocks service or not.<br />
# service iptables stop|start : To start|stop iptables<br />
# more /etc/xinetd.conf</p>
<p><strong>sar </strong><br />
sar is an excellent monitoring tool that displays performance data of pretty much every resource of the system including CPU, memory, IO, paging, networking, interrupts etc., Sar Collects, Reports (displays) and Saves the performance data<strong>.</strong></p>
<p># sar –u | more         Display CPU Statistics using Sar Command<br />
# sar –d | more         Display Disk IO Statistics using sar command<br />
# sar -n DEV | more Display networking Statistics using sar command<br />
# sar -n SOCK |more Display networking Statistics using sar command<br />
# sar -n DEV -f /var/log/sa/sa24 | more   To display the network counters from the 24th<br />
# sar 4 5                                             You can also display real time usage using sar</p>
<p><strong>lsof</strong><br />
lsof stands for &#8220;ls open files&#8221;, which will list all the open files in the system. The open files include network connection, devices and directories. The output of the lsof command will have the following columns:</p>
<p>COMMAND process name.<br />
PID process ID<br />
USER Username<br />
FD file descriptor<br />
TYPE node type of the file<br />
DEVICE device number<br />
SIZE file size<br />
NODE node number<br />
NAME full path of the file name.</p>
<p># lsof | more              View all open files of the system<br />
# lsof | wc -l                How many files are open in the system at any given point<br />
# lsof –u ramesh       View open files by a specific user. A system administrator can use this command to get some idea on what users are executing on the system.<br />
# lsof /bin/vi               it displays all users who are currently using vi</p>
<p><strong>Some external Tools</strong><br />
iptraf &#8211; Real-time Network Statistics<br />
tcpdump  &#8211; Detailed Network Traffic Analysis<br />
Nagios &#8211; Server And Network Monitoring<br />
Cacti &#8211; Web-based Monitoring Tool<br />
KDE System Guard &#8211; Real-time Systems Reporting and Graphing<br />
Gnome System Monitor &#8211; Real-time Systems Reporting and Graphing<br />
nmap &#8211; scan your server for open ports.<br />
lsof &#8211; list open files, network connections and much more.<br />
ntop web based tool &#8211; ntop is the best tool to see network usage in a way similar to what top command does for processes i.e. it is network traffic monitoring software. You can see network status, protocol wise distribution of traffic for UDP, TCP, DNS, HTTP and other protocols.<br />
Conky &#8211; Another good monitoring tool for the X Window System. It is highly configurable and is able to monitor many system variables including the status of the CPU, memory, swap space, disk storage,<br />
temperatures, processes, network interfaces, battery power, system messages, e-mail inboxes etc.<br />
GKrellM &#8211; It can be used to monitor the status of CPUs, main memory, hard disks, network interfaces, local and remote mailboxes, and many other things.<br />
vnstat &#8211; vnStat is a console-based network traffic monitor. It keeps a log of hourly, daily and monthly network traffic for the selected interface(s).<br />
htop &#8211; htop is an enhanced version of top, the interactive process viewer, which can display the list of processes in a tree form.<br />
mtr &#8211; mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.</p>
<p>yum<br />
Rsync<br />
rpm – Refer Cheat Book</p>
<p><strong>Some Well known System services</strong><br />
QUICK DNS Flush                             /etc/rc.d/init.d/nscd restart<br />
/Proc file system &#8211; Various Kernel Statistics<br />
# cat /proc/cpuinfo<br />
# cat /proc/meminfo<br />
# cat /proc/zoneinfo<br />
# cat /proc/mounts</p>
<p><strong>Questions</strong><br />
What is MASK in output of ifconfig<br />
Understand the output of ifconfig in linux such as RX packets and TX packets<br />
Set ip address using commands line</p>
<p><strong>Change Host name in RHEL</strong><br />
Changes should be made in the following files.<br />
/etc/hosts<br />
/etc/sysconfig/network</p>
<p><strong>For finding your java process</strong><br />
jps -v      For finding your java process.<br />
jstack PID  To Get stack of threads inside jvm</p>
<p><strong>If application running under different user than yourself</strong><br />
sudo jps -v<br />
sudo jstack 6172</p>
<table border="0" width="1464" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="bottom" nowrap="nowrap" width="712"><strong>QUICK DNS Flush</strong><br />
/etc/rc.d/init.d/nscd restart</td>
<td nowrap="nowrap" width="752">/etc/rc.d/init.d/nscd restart</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="712"><strong>Reference</strong><br />
<a href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch04_:_Simple_Network_Troubleshooting">http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch04_:_Simple_Network_Troubleshooting</a><br />
<a href="http://www.cyberciti.biz/tips/linux-security.html">http://www.cyberciti.biz/tips/linux-security.html</a><br />
<a href="http://www.cyberciti.biz/tips/list-of-linux-troubleshooting-commandstools-part-1.html">http://www.cyberciti.biz/tips/list-of-linux-troubleshooting-commandstools-part-1.html</a><br />
<a href="http://www.princeton.edu/~unix/Solaris/troubleshoot/index.html">http://www.princeton.edu/~unix/Solaris/troubleshoot/index.html</a><br />
<a href="http://www.techbooksforfree.com/intro_to_data_com/page252.html">http://www.techbooksforfree.com/intro_to_data_com/page252.html</a><br />
<a href="unix-linux/linux-performance-monitoring-using-iostat-mpstat-and-vmstat.html">http://www.scmgalaxy.com/unix-linux/linux-performance-monitoring-using-iostat-mpstat-and-vmstat.html</a></p>
<p><a href="http://www.tecmint.com/20-advanced-commands-for-linux-experts/">http://www.tecmint.com/20-advanced-commands-for-linux-experts/</a></td>
<td nowrap="nowrap" width="752"></td>
</tr>
</tbody>
</table>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/linux-commands-for-administrator/">Linux Commands for Administrator | Linux Admin Commands Reference</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/linux-commands-for-administrator/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Linux Commands for User &#124; Linux User Commands Reference</title>
		<link>https://www.scmgalaxy.com/tutorials/linux-commands-for-user/</link>
					<comments>https://www.scmgalaxy.com/tutorials/linux-commands-for-user/#respond</comments>
		
		<dc:creator><![CDATA[scmgalaxy K]]></dc:creator>
		<pubDate>Mon, 21 Jul 2014 00:00:00 +0000</pubDate>
				<category><![CDATA[Unix - Linux]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux Commands]]></category>
		<category><![CDATA[Linux Commands for User Guide]]></category>
		<category><![CDATA[Linux Commands for User Reference]]></category>
		<category><![CDATA[Linux Commands for User Tutorials]]></category>
		<category><![CDATA[Linux Commands for Users]]></category>
		<category><![CDATA[Linux Commands Guide]]></category>
		<category><![CDATA[Linux Commands Reference]]></category>
		<category><![CDATA[Linux Commands Tutorials]]></category>
		<category><![CDATA[Linux User Commands Guide]]></category>
		<category><![CDATA[Linux User Commands Tutorials]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[Users Linux Commands]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/2014/07/21/linux-commands-for-user/</guid>

					<description><![CDATA[<p>General Commands Not Used Frequently cal – The Calender bc – The Calculator file – knowing the file types cmp [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/linux-commands-for-user/">Linux Commands for User | Linux User Commands Reference</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignnone size-full wp-image-3671 aligncenter" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2014/07/linux-commands-user.png" alt="linux-commands-user" width="600" height="400" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2014/07/linux-commands-user.png 600w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2014/07/linux-commands-user-300x200.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p><strong>General Commands Not Used Frequently</strong><br />
cal – The Calender<br />
bc – The Calculator<br />
file – knowing the file types<br />
cmp – Comparing two files.<br />
comm – Common in two files<br />
dos2unix and unix2dos – Converting between dos and unix<br />
stat &#8211; Display file or file system status such as Access, Modify,Change, users and more<br />
# stat &lt;fileName&gt; unix Command</p>
<p><strong>General Commands Frequently Used</strong><br />
Script – recording your session<br />
Passwd – change your password<br />
Echo  &#8211; Displaying the message<br />
Printf &#8211; Displaying the message<br />
who – Who are the Users<br />
who am I – To know my user name<br />
uname – Knowing your machine characteristics<br />
# uname –a  &#8211; To Print all info.<br />
tty – knowing your terminal<br />
pwd – Checking Current Directory<br />
cd &#8211; changing the current Directory<br />
mkdir – Making directories<br />
rmdir – removing directories<br />
<strong>ls – Listing Directory Contents</strong><br />
# ls –F – Marks executables with *, directories with / and symbolic links with @ at the end of file name.<br />
# ls – a – Shows all filesnames including beginning with a dot.<br />
# ls –R – Recursive display list of files and folders<br />
# ls -1 – one filename in each line<br />
# ls –l long listing + time of last file modification<br />
# ls –t Sorts filenames by last modification time<br />
# ls –u – Sorts filenames by last access time<br />
# ls –I – Displays inode number<br />
# ls –lc – Time of last inode modifcation</p>
<p><strong>Cat – Displaying and creating Files</strong><br />
# cat filename – Displaying file contents<br />
# cat –n filename &#8211; Displaying file contents with line numbers<br />
# cat &gt; filename – To Create a file name</p>
<p><strong>More – Paging Output</strong><br />
# more filename – To to display the filename contents</p>
<p><strong>Less – Paging Output</strong></p>
<p><strong>wc – Counting lines, Words and Characters</strong><br />
# -l – Option counts only the number of lines<br />
# -w – Option counts only the words.<br />
# -c – Options counts only the characters.</p>
<p><strong>cp – copying a files</strong><br />
Options<br />
# -p – Copy the files including preserve the mode, ownership and permissions.<br />
# -R – Copying Directory Structure</p>
<p><strong>gzip and gunzip – Compressing and Decompressing Files</strong><br />
# gzip filename<br />
# gzip –l – To find out how much of the compression was archived.<br />
# gzip –d filename – To Decompress a file<br />
# gunzip filename – To Decompress a file<br />
# gzip –R dir – To Compress Recursive</p>
<p><strong>Tar – The archival Program</strong><br />
# -c – To create a archive<br />
# -x – Extract files from archive<br />
# -t – Display fils in archive<br />
# -v – verbose<br />
# -f – name of the arch filename .tar<br />
# tar –cvf filename.tar filename1 filename2<br />
# tar –xvf filename.tar</p>
<p><strong>Create tar and gzip</strong><br />
# tar cvf &#8211; foodir | gzip &gt; foo.tar.gz</p>
<p><strong>Un-tar and gunzip</strong><br />
# tar -zxvf apache-activemq-5.1.0-bin.tar.gz</p>
<p><strong>Un-tar and uncompress using gunzip</strong><br />
# gunzip -c apache-activemq-5.1.0-bin.tar.gz | tar xvf &#8211;<br />
or alternatively:<br />
# gunzip apache-activemq-5.1.0-bin.tar.gz | tar xvf &#8211;</p>
<p><strong>File Attributes</strong><br />
<strong>chmod – Changing File Permission</strong></p>
<p>Abbreviations Used by chmod</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="160"><strong>Category</strong></td>
<td valign="top" width="160"><strong>Operation</strong></td>
<td valign="top" width="160"><strong>Permission</strong></td>
<td valign="top" width="160"><strong>Assigned Number</strong></td>
</tr>
<tr>
<td valign="top" width="160">u -user</td>
<td valign="top" width="160">+ &#8211; Assigns Permission</td>
<td valign="top" width="160">r – Read permission</td>
<td valign="top" width="160">4</td>
</tr>
<tr>
<td valign="top" width="160">g -group</td>
<td valign="top" width="160">&#8211;  &#8211; Assigns Permission</td>
<td valign="top" width="160">w – Write Permission</td>
<td valign="top" width="160">2</td>
</tr>
<tr>
<td valign="top" width="160">o – other</td>
<td valign="top" width="160">= &#8211; Assigns Permission</td>
<td valign="top" width="160">x – Execute Permission</td>
<td valign="top" width="160">1</td>
</tr>
<tr>
<td valign="top" width="160">a –all(ugo)</td>
<td valign="top" width="160"></td>
<td valign="top" width="160"></td>
<td valign="top" width="160"></td>
</tr>
</tbody>
</table>
<p>Example:<br />
# chmod u+x filename<br />
# chmod u+x filename<br />
# chmod ugo+x filename<br />
# chmod u+x filename1 filename2 filename3<br />
# chmod a-x,go+r filename<br />
# chmod 566 filename<br />
# chmod 755 filename<br />
# chmod –R 755 .<br />
# chmod –R a+x *</p>
<p><strong>Chown – Changing File Ownership</strong><br />
# chown username filename<br />
More example needed.</p>
<p><strong>Shell’s Wild-Cards</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="149"><strong>Wild-Card</strong></td>
<td valign="top" width="489"><strong>Matches</strong></td>
</tr>
<tr>
<td valign="top" width="149"><strong>*</strong></td>
<td valign="top" width="489">Any numbers of characters including none</td>
</tr>
<tr>
<td valign="top" width="149"><strong>?</strong></td>
<td valign="top" width="489">A single character</td>
</tr>
<tr>
<td valign="top" width="149"><strong>[ijk]</strong></td>
<td valign="top" width="489">A single character – either I,j or k</td>
</tr>
<tr>
<td valign="top" width="149"><strong>[x-z]</strong></td>
<td valign="top" width="489">A single character that is within the ASCII range of the characters x and z</td>
</tr>
<tr>
<td valign="top" width="149"><strong>[!ijk]</strong></td>
<td valign="top" width="489">A single character that is not an I,j, or k</td>
</tr>
<tr>
<td valign="top" width="149"><strong>[!x-z]</strong></td>
<td valign="top" width="489">A single character that is not within the ASCII range of the characters x and z</td>
</tr>
<tr>
<td valign="top" width="149"><strong> </strong></td>
<td valign="top" width="489"></td>
</tr>
</tbody>
</table>
<p><strong>Ps – Process Status</strong><br />
<strong>Options to ps</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="158"><strong>POSIX Options</strong></td>
<td valign="top" width="480"><strong>Significance</strong></td>
</tr>
<tr>
<td valign="top" width="158"><strong>-f</strong></td>
<td valign="top" width="480">Full listing showing the PPID of each process</td>
</tr>
<tr>
<td valign="top" width="158"><strong>-e or –A</strong></td>
<td valign="top" width="480">All Process including user and Systems</td>
</tr>
<tr>
<td valign="top" width="158"><strong>-u usr</strong></td>
<td valign="top" width="480">Process of user usr only</td>
</tr>
<tr>
<td valign="top" width="158"><strong>-a</strong></td>
<td valign="top" width="480">Processes of all users excluding processes not associated with terminal</td>
</tr>
<tr>
<td valign="top" width="158"><strong>-l</strong></td>
<td valign="top" width="480">A long listing showing memory-related information</td>
</tr>
</tbody>
</table>
<p><strong>Example</strong><br />
# ps -ef<br />
# ps –u sumit<br />
# ps –a<br />
# ps –e<br />
# ps -A &#8211; ps command will report a snapshot of the current processes. To select all processes use the -A<br />
# ps -Al &#8211; Show Long Format Output<br />
# ps -AlF &#8211; To turn on extra full mode (it will show command line arguments passed to process):<br />
# ps axu &#8211; Print All Process On The Server<br />
# ps -U vivek -u vivek u &#8211; See Every Process Running As User Vivek<br />
# ps -p 55977 -o comm= &#8211; Display The Name of PID 55977<br />
# ps -auxf | sort -nr -k 4 | head -10 &#8211; Find Out The Top 10 Memory Consuming Process<br />
# ps -auxf | sort -nr -k 3 | head -10 &#8211; Find Out top 10 CPU Consuming Process</p>
<p># $! – Store the PID of the last background jobs<br />
# echo $$  &#8211; To Know the PID of current Shell<br />
# echo $SHELL – To Know the Current Shell<br />
# System process easily identifies the ? in the TTY coloumn.<br />
# Mechanism of Process Creation<br />
Fork<br />
Exec<br />
Wait</p>
<p><strong>&amp; and nohup – Ruunning jobs in background</strong><br />
# nohup sort emp.lst $</p>
<p><strong>nice – Job execution with low priority</strong><br />
Kernel decides how much processor time is required for a process based on the nice value. Possible nice value range is: -20 to 20. A process that has a nice value of -20 is very high priority. The process that has a nice value of 20 is very low priority.<br />
Use ps axl to display the nice value of all running process as shown below.<br />
# ps axl<br />
# nice command is used with &amp; operator to reduce the priority of jobs<br />
# nice script.sh &amp;<br />
# ./nice-test.sh &amp;                             Default the nice value of 0<br />
# nice -10 ./nice-test.sh &amp;            Nice value is 10                 Low priority.<br />
# nice &#8211;10 ./nice-test.sh &amp;          Nice value is -10                High priority.</p>
<p><strong>Kill – killing the process</strong><br />
# kill PID<br />
# kill PID1 PID2 PID3<br />
# kill $i – Killing the last background process<br />
# kill –s KILL PID – recommended way for killing (SIGKILL)<br />
# kill -9 PID – same as above but not recommended. (SIGKILL)<br />
# kill -9 $$  -$$ store the PID of current shell<br />
# kill –s KILL 0 – kill all the process including the login shell.<br />
# kill –l – To View the list of all signal names and numbers that are available on your machine.<br />
# kill %1 – Kill first background jobs</p>
<p><strong>Jobs </strong><br />
List the background jobs in following fashion<br />
[3] +       running                                command<br />
[1] &#8211;        running                                command<br />
[2]          running                                command</p>
<p><strong>bg – Convert Jobs to background</strong><br />
# if you have invoked a command and the prompt has not yet return, you can suspend the job by pressing Ctrl-Z. Observe that job has not been terminated yet; its onl y suspended (“stopped”). Now you can use bg command to push the current foreground job in the background.<br />
# bg %2 – Sends second job to background<br />
# bg %sort &#8211; Sends sort job to background</p>
<p><strong>fg – bring background job to foreground</strong><br />
# fg – To bring most recent job to forground<br />
# fg %1 – Bring First job to foreground<br />
# fg %2 – Bring second job to foreground<br />
# fg %sort &#8211; Bring sort job to foreground</p>
<p><strong>at – On time execution</strong><br />
# at 14:08<br />
at &gt; script.sh<br />
[ctrl-d]</p>
<p><strong>Batch – execute when system resources are available</strong><br />
# batch &lt; script.sh</p>
<p><strong>Cron – Schedule and run jobs periodically</strong><br />
# crontab –e – To Edit the cron tab<br />
# crontab –l – To Display the cron tab<br />
# crontab cron.tx – cron.txt contains cron commands<br />
# crontab –r – To Remove the cron</p>
<p>Format of crontab – TODO</p>
<p><strong>Customizing the environment</strong></p>
<p># set – set statemtent display a complete list of all environment variable<br />
# PATH =$PATH:/usr/xpg4/bin – Adding new value to old values<br />
# PS1 =”C&gt; “ – To Change the prompt<br />
# PS1=’[$PWD] ‘ – To Change the prompt to pwd<br />
# alias cp=”cp –I” – To Set the alias in bash<br />
# history – To See the history<br />
# IFS – Field Separators for commands and arguments<br />
# !! – Repeat Previous commands<br />
# !2 – Repeat commands 2 from history output<br />
# !-2 – Execute the commands prior to previous one<br />
# !v – Execture very last commands beginning withg v<br />
# $_ &#8211; Using last arugement of previous commands<br />
# mkdir raj<br />
# cd $_</p>
<p><strong>ln – Hard Links and Softlinks</strong><br />
# ln /usr/bin/perl  /usr/local/bin/perl – To create a hard links from src to dest<br />
# ls –I  &#8211; To Display the node number of files<br />
# ln –s /usr/bin/perl  /usr/local/bin/perl – To Create a soft link</p>
<p><strong>umask – default file and directory permission</strong><br />
# When you create a files and directories, the permission assigned to them depends on rge system’s default setting..<br />
# unix has default 666 for regular files &amp; 777 for directories<br />
# umask –ENTER<br />
# 022<br />
This is an octal number which has to be subtracted from system default to obtain the actual default. This becomes 644 (666-022) for ordinary files and 755 ( 777 -022) for directories.<br />
# User can set the umask such as umask 023.</p>
<p><strong>touch – Changing the time stamp</strong><br />
# touch emp.lst – Create a file name called emp.lst<br />
# touch 02161430 emp.lst – To Change the time stamp of file for MMDDhhmm format<br />
# touch –a 02161430 emp.lst – To Change the access time stamp of file for MMDDhhmm format<br />
# touch –m 02161430 emp.lst – To Change the modification time stamp of file for MMDDhhmm format</p>
<p><strong>find – Locating files</strong></p>
<p><strong>Expression Used by find.</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="149">Expression</td>
<td valign="top" width="489">Use</td>
</tr>
<tr>
<td valign="top" width="149">-inum n</td>
<td valign="top" width="489">Having inode number n</td>
</tr>
<tr>
<td valign="top" width="149">-type x</td>
<td valign="top" width="489">if of type x can include files, directories or symbolic link</td>
</tr>
<tr>
<td valign="top" width="149">-type f</td>
<td valign="top" width="489">If an ordinary file</td>
</tr>
<tr>
<td valign="top" width="149">-perm nnn</td>
<td valign="top" width="489">If octal permission match nnn completely</td>
</tr>
<tr>
<td valign="top" width="149">-links n</td>
<td valign="top" width="489">If having n links</td>
</tr>
<tr>
<td valign="top" width="149">-user usname</td>
<td valign="top" width="489">If owner by usname</td>
</tr>
<tr>
<td valign="top" width="149">-group gname</td>
<td valign="top" width="489">If owned by group gname</td>
</tr>
<tr>
<td valign="top" width="149">-size +x[C]</td>
<td valign="top" width="489"></td>
</tr>
<tr>
<td valign="top" width="149">-mtime –x</td>
<td valign="top" width="489">If modified in less than x days</td>
</tr>
<tr>
<td valign="top" width="149">-newer filename</td>
<td valign="top" width="489">If modified after filename</td>
</tr>
<tr>
<td valign="top" width="149">-mmin –x</td>
<td valign="top" width="489">If modified in less than x minutes</td>
</tr>
<tr>
<td valign="top" width="149">-atime +x</td>
<td valign="top" width="489">If accessed in more than x days</td>
</tr>
<tr>
<td valign="top" width="149">-amin +x</td>
<td valign="top" width="489">If accessed in more than x minutes</td>
</tr>
<tr>
<td valign="top" width="149">-name filename</td>
<td valign="top" width="489">Filename</td>
</tr>
<tr>
<td valign="top" width="149"><strong>Action</strong></td>
<td valign="top" width="489"><strong>Significance</strong></td>
</tr>
<tr>
<td valign="top" width="149">-print</td>
<td valign="top" width="489">Prints selected file on standard output</td>
</tr>
<tr>
<td valign="top" width="149">-ls</td>
<td valign="top" width="489">Executes ls –lids commands on selected files</td>
</tr>
<tr>
<td valign="top" width="149">-exec cmd</td>
<td valign="top" width="489">Executes UNIX command cmd followed by {} \;</td>
</tr>
<tr>
<td valign="top" width="149">-ok cmd</td>
<td valign="top" width="489">Like –exec, except that command is executed after user confirmation</td>
</tr>
</tbody>
</table>
<p><strong>Example</strong></p>
<p>Change File Permissions Recursively<br />
# find . -type f -exec chmod 644 {} \;<br />
# find . -type d -exec chmod 755 {} \;<br />
# find . -name Configuration.php -exec chmod 666 {} \;</p>
<p>Find files modified in the last 48 hours, and in current folder and one level below<br />
# find -maxdepth 2 -type f -mtime -2</p>
<p>To find all files modified in the last 24 hours (last full day) in a particular specific directory and its sub-directories:<br />
# find /directory_path -mtime -1 –print</p>
<p>To find all files with regular file types only, and modified in the last 24 hours (last full day) in current directory and its sub-directories:<br />
# find /directory_path -type f -mtime -1 –print<br />
# find . -type f -mtime -1 –print</p>
<p>To find all files that are modified today only (since start of day only, i.e. 12 am), in current directory and its sub-directories:<br />
# touch -t `date +%m%d0000` /tmp/$$<br />
# find /tmefndr/oravl01 -type f -newer /tmp/$$<br />
# rm /tmp/$$</p>
<p>To find all files in /home/user/demo directory<br />
# find /home/user/demo -type f –print</p>
<p>To find all files in /home/user/demo directory with permission 777, enter:<br />
# find /home/user/demo -type f -perm 777 –print</p>
<p>Apply new permission using the -exec option as follows:<br />
# find /home/user/demo -type f -perm 777 -print -exec chmod 755 {} \;</p>
<p>To select directories and subdirectories use the following syntax:<br />
# find /var/www/html -type d -perm 777 -print -exec chmod 755 {} \;</p>
<p>This first Linux find example searches through the root filesystem (&#8220;/&#8221;) for the file named &#8220;Chapter1&#8221;. If it finds the file, it prints the location to the screen.<br />
# find / -name Chapter1 -type f –print</p>
<p>A nice thing to know is that on Linux systems and modern Unix system you no longer need the -print option at the end of the find command, so you can issue it like this:<br />
# find / -name Chapter1 -type f</p>
<p>This next find command searches through the /usr and /home directories for the file named Chapter1:<br />
# find /usr /home -name Chapter1 -type f</p>
<p>To search in the current directory, and all subdirectories, just use the . character to reference the current directory in your find commands, like this:<br />
# find . -name Chapter1 -type f</p>
<p>This next command searches through the /usr directory for all files that begin with the letters Chapter, followed by anything else. The filename can end with any other combination of characters. It will match filenames such as Chapter, Chapter1, Chapter1.bad, Chapter-in-life, etc.:<br />
# find /usr -name &#8220;Chapter*&#8221; -type f</p>
<p>This next command searches through the /usr/local directory for files that end with the extension .html. These file locations are then printed to the screen.<br />
# find /usr/local -name &#8220;*.html&#8221; -type f</p>
<p>To find all directories named build under the current directory, use this command:<br />
# find . -type d -name build</p>
<p>This command searches through the htdocs and cgi-bin directories for files that end with the extension .cgi. When these files are found, their permission is changed to mode 755 (rwxr-xr-x). This example shows that the find command can easily search through multiple sub-directories (htdocs, cgi-bin) at one time.<br />
# find htdocs cgi-bin -name &#8220;*.cgi&#8221; -type f -exec chmod 755 {} \;</p>
<p>Find and display files last modified les than 90 days ago.<br />
# find . -name &#8220;*&#8221; -mtime -3 -print</p>
<p>find everything in your home that has been modified more recently than &#8220;abc.txt&#8221;:<br />
# find $HOME -newer ~joeuser/lastbatch.txt</p>
<p>For finding only files from all directories recursively<br />
# find ./ -type f | wc -l</p>
<p>For finding only files from all directories recursively<br />
# find ./ &#8211; type d | wc -l</p>
<p>How to Return a message when a file is not found using find command? OR<br />
Find command return type OR<br />
when the file is not found i want it to return some value OR<br />
# find . -name raj.txt &gt; raj.txt<br />
# counter= `cat abc.txt | wc -l&#8217;<br />
# if [$counter -gt 0]<br />
# then<br />
#                echo &#8220;File is found&#8221;<br />
# else<br />
#                echo &#8220;File is not found&#8221;<br />
# fi<br />
<strong>That&#8217;s nice, but what if I want to see the last modification time of these files, or their filesize? No problem, I just add the &#8220;ls -ld&#8221; command to my find command, like this:</strong><br />
find . -name &#8220;*.pl&#8221; -exec ls -ld {} \;</p>
<p>Count Total number of files in Directory and Subdirectory<br />
# find . -type f | wc –l</p>
<p>Count Specific extention files in Directory and Subdirectory<br />
# find . -type f -name \*.mnp |wc –l</p>
<p>Count only Directory<br />
# find . -type d | wc –l</p>
<p><strong>head – Displaying the beginning of a file</strong><br />
# head –n 3 filename<br />
# vi `ls –t` | head –n 1` &#8211; Opens last modified file for editing</p>
<p><strong>tail – Displaying the end of a file</strong><br />
<strong># tail -3 filename</strong><br />
<strong># tail –f filename             Monitering file live</strong></p>
<p><strong>Cut</strong><br />
# cut –c 6-12,24-32 filename – Cutting column<br />
# cut –d \| -f 2,3 filename            &#8211; Cutting fields<br />
# cut –d “|” –f 1,4- filename –To cut out the fields numbered 1,4,5 and 6.</p>
<p><strong>Sort – Ordering a file</strong><br />
<strong>Sort Options</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121"><strong>Option</strong></td>
<td valign="top" width="518"><strong>Description</strong></td>
</tr>
<tr>
<td valign="top" width="121"><strong>-tchar</strong></td>
<td valign="top" width="518">Use delimiter char to identify fields</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-k n</strong></td>
<td valign="top" width="518">Sorts on nth field</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-k m,n</strong></td>
<td valign="top" width="518">Start sort on mth field and end sort on nth field</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-k m.n</strong></td>
<td valign="top" width="518">Start sort on nth column of mth field</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-u </strong></td>
<td valign="top" width="518">Removes repeated lines</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-n </strong></td>
<td valign="top" width="518">Sort numerically</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-r </strong></td>
<td valign="top" width="518">Reverse sort order</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-m list</strong></td>
<td valign="top" width="518">Merge sorted files in list</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-c</strong></td>
<td valign="top" width="518">Checks of file sorted</td>
</tr>
<tr>
<td valign="top" width="121"><strong>-o filename</strong></td>
<td valign="top" width="518">Place output in file filename</td>
</tr>
</tbody>
</table>
<p><strong>Examples:</strong><br />
# sort –t”|” –k 2 shortlist<br />
# sort –t”|” –r –k 2 shortlist<br />
# sort –t “|” –k 3,3 –k 2,2 shortlist<br />
# sort –t”|” –k 5.7,5.8 shortlist<br />
# sort numfile<br />
# cut –d”|” –f3 filename | sort –u<br />
# sort –m foo1 foo2 foo3</p>
<p><strong>Uniq – Locate repeated and non-repeated lines</strong><br />
# sort dept.lst | uniq<br />
# cut –d”|” –f3 emp.lst | sort | uniq –u                                 ( -u selects only lines which is not repeated)<br />
# cut –d”|” –f3 emp.lst | sort | uniq –d                                 ( -d selects one copy of repeated lines)<br />
# cut –d”|” –f3 emp.lst | sort | uniq –c</p>
<p><strong>tr – Translating characters</strong><br />
# tr ‘|/’ ‘~-‘ &lt; emp.lst | head –n 3             – To replace the | with a ~ and the / with a  -.<br />
# head –n 3 emp.lst | tr ‘[a-z]’ ‘[A-Z]’     – Change first three lines from lower to upper.<br />
# tr –d ‘|’ &lt; emp.lst | head –n 3                                – To deleting characters</p>
<p><strong>grep – Searching for a pattern</strong><br />
# grep “director” filename1 filename2<br />
# grep “Rajesh Kumar” filename1<br />
# grep –i ‘rajesh’ filename1                                         To Ignore case<br />
# grep –v ‘rajesh’ filename1 &gt; filename2                              To Select all except lines containing patterns<br />
# grep –n ‘rajesh’ filename1                                       To Display line numbers<br />
# grep –c ‘rajesh’ filename                                          Counting line containing pattern<br />
# grep –l ‘rajesh’ *.lst                                                    -l options display only the name of files containing pattern<br />
# grep –f pattern.lst emp.lst                                       Taking patterns from files</p>
<p><strong>Grep a file, but show several surrounding lines?</strong></p>
<p>For BSD or GNU grep you can use -B num to set how many lines before the match and -A num for th number of lines after the match.<br />
grep -B 3 -A 2 foo README.txt</p>
<p>If you want the same amount of lines before and after you can use -C num.<br />
grep -C 3 foo README.txt<br />
This will show 3 lines before and 3 lines after.</p>
<p><strong>Basic Regular Expression tables</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="158"><strong>Symbols or Expressions</strong></td>
<td valign="top" width="480"><strong>Matches</strong></td>
</tr>
<tr>
<td valign="top" width="158"><strong>*</strong></td>
<td valign="top" width="480">Zero or more occurrances of the previous character</td>
</tr>
<tr>
<td valign="top" width="158"><strong>g*</strong></td>
<td valign="top" width="480">Nothing or g,gg,ggg, etc</td>
</tr>
<tr>
<td valign="top" width="158"><strong>.</strong></td>
<td valign="top" width="480">A Single Character</td>
</tr>
<tr>
<td valign="top" width="158"><strong>.*</strong></td>
<td valign="top" width="480">Nothing or any number of character</td>
</tr>
<tr>
<td valign="top" width="158"><strong>[pqr]</strong></td>
<td valign="top" width="480">A single character p, q or r</td>
</tr>
<tr>
<td valign="top" width="158"><strong>[c1-c2]</strong></td>
<td valign="top" width="480">A Single Character with ASCII range</td>
</tr>
<tr>
<td valign="top" width="158"><strong>[1-3]</strong></td>
<td valign="top" width="480">A single digit between 1 and 3</td>
</tr>
<tr>
<td valign="top" width="158"><strong>[^pqr]</strong></td>
<td valign="top" width="480">A Single character which is not a p,q or r</td>
</tr>
<tr>
<td valign="top" width="158"><strong>[^a-zA-Z]</strong></td>
<td valign="top" width="480">A non-alphabetic character</td>
</tr>
<tr>
<td valign="top" width="158"><strong>^pat</strong></td>
<td valign="top" width="480">Pattern pat at the beginning of the line</td>
</tr>
<tr>
<td valign="top" width="158"><strong>pat$</strong></td>
<td valign="top" width="480">Pattern pat at the end of the line</td>
</tr>
<tr>
<td valign="top" width="158"><strong>bash$</strong></td>
<td valign="top" width="480">Bash at the end of the line</td>
</tr>
<tr>
<td valign="top" width="158"><strong>^bash$</strong></td>
<td valign="top" width="480">Bash as the only one word in line</td>
</tr>
<tr>
<td valign="top" width="158"><strong>^$</strong></td>
<td valign="top" width="480">Line containing nothing</td>
</tr>
<tr>
<td valign="top" width="158"><strong>+</strong></td>
<td valign="top" width="480">Matches one or more character of previous character</td>
</tr>
<tr>
<td valign="top" width="158"><strong>?</strong></td>
<td valign="top" width="480">Matches zero or one occurrence of the previous character</td>
</tr>
<tr>
<td valign="top" width="158"><strong>|</strong></td>
<td valign="top" width="480">Delimiter for multiple pattern</td>
</tr>
<tr>
<td valign="top" width="158"><strong>( )</strong></td>
<td valign="top" width="480">Group pattern</td>
</tr>
</tbody>
</table>
<p><strong>Example:</strong><br />
# grep “[aA]g[ar][ar]wal filename<br />
# grep “[aA]gg*[ar][ar]wal” filename<br />
# grep “j.*Saxena” filename<br />
# grep “^2” filename<br />
# grep “7…$” filename<br />
# grep “^[^2]” filename<br />
# grep –E “[aA]gg?arwal” filename<br />
# grep –E ‘sengupta|dasgupta’ filename<br />
# grep –E ‘(sen|das)gupta’ filename</p>
<p><strong>Editor</strong><br />
Awk  &#8211; http://www.thegeekstuff.com/2010/01/awk-introduction-tutorial-7-awk-print-examples/<br />
Sed<br />
vi</p>
<p># sed – The Stream Editor<br />
# sed ‘3q’ filename == head –n 3                              Quit after line number 3<br />
# sed –n ‘1,2p’ filename                                                               Prints the first 2 lines. Must use –n with p<br />
# sed –n ‘$p’ filename                                                   print last line<br />
# sed –n ‘9,11p 7,9p $p’ filename<br />
# sed –n ‘3,$ip’ filename                                              Don’t print line 3 to the end, display only line 1 and 2</p>
<p># sed –n ‘/director/p’ filename                                 To print the lines which has pattern in filename<br />
# sed –n ‘/dasgupta/,/saksena/p’ filename<br />
# sed –n ‘1,/dasgupta/p’ filename<br />
# sed –n ‘/[aA]gg*[ar][ar]wal/p’ filename<br />
# sed –n ‘/sa[kx]s*ena/p /Gupta/p’ filename<br />
# sed –n ‘/50…..$/p’ filename</p>
<p># sed –n ‘director/w  dlsit’ filename<br />
# sed –n ‘director/w dlist /manager/w mlist /executive/w elist’ filename<br />
# sed –n ‘1,500w foo1 501,$w foo2’ filename</p>
<p># sed ‘1i\<br />
&gt; #include &lt;stdio.h&gt;\<br />
&gt; #include&lt;unistd.h&gt;<br />
&gt;’ foo.c  &gt;&gt; $$                                                                    Include these include on beginning of the program<br />
# sed ‘a\</p>
<p>‘ filename                                                                            # insert after every line this blank line<br />
# sed “/director/d’ filename &gt; filename2              -n option not to be used with d<br />
== # grep –v “director” filename &gt; filename2<br />
# sed –n ‘/director/!p’ filename1 &gt; filename2</p>
<p># sed ‘s/|/:/’ filename | head -2<br />
# sed ‘s/|/:/g’ filename | head -2<br />
# sed ‘1,3s/|/:/g’ filename<br />
# sed ‘1,5s/director/member /’ filename<br />
# sed ‘s/^/2’ filename<br />
# sed ‘s/$.00/’ filename</p>
<p><strong>Sed tables</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="130">Command</td>
<td valign="top" width="508">Description</td>
</tr>
<tr>
<td valign="top" width="130">I,a,c</td>
<td valign="top" width="508"><strong>Insert, Appends and Changes text</strong></td>
</tr>
<tr>
<td valign="top" width="130">d</td>
<td valign="top" width="508"><strong>Delete lines</strong></td>
</tr>
<tr>
<td valign="top" width="130">10q</td>
<td valign="top" width="508"><strong>Quit after reading the first 10 lines</strong></td>
</tr>
<tr>
<td valign="top" width="130">p</td>
<td valign="top" width="508"><strong>Print line on standard outputs</strong></td>
</tr>
<tr>
<td valign="top" width="130">3,$p</td>
<td valign="top" width="508"><strong>Print lines 3 to the end. –n option is required</strong></td>
</tr>
<tr>
<td valign="top" width="130">$!p</td>
<td valign="top" width="508"><strong>Prints all lines except last line. –n option required</strong></td>
</tr>
<tr>
<td valign="top" width="130">/begin/,/end/p</td>
<td valign="top" width="508"><strong>Print lines enclosed between begin and end. –n option required</strong></td>
</tr>
<tr>
<td valign="top" width="130">q</td>
<td valign="top" width="508"><strong>Quit after reading uo to the address line</strong></td>
</tr>
<tr>
<td valign="top" width="130"></td>
<td valign="top" width="508"><strong> </strong></td>
</tr>
</tbody>
</table>
<p><strong>Vi &#8211; Editor                            </strong></p>
<p><strong>IMPORTANT – YOU SHOULD USE DOUBLE QUOTES ONLY WHEN PARAMETER EVALULATION OR command substitution is embedded within command</strong></p>
<p>Write about command “w”</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/linux-commands-for-user/">Linux Commands for User | Linux User Commands Reference</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/linux-commands-for-user/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
