<?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 for User Reference Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/linux-commands-for-user-reference/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/linux-commands-for-user-reference/</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 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 fetchpriority="high" 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>
