Skip to main content

Touch & More


Touch

touch [-acm] [-f agefile] [-r agefile] [[-t] time] file ...

touch [-acm] time file ...
DESCRIPTION

The touch command changes certain dates for each file argument. By default, touch sets both the date of last file modification and the date of last file access to the current time. This is useful for maintaining correct release times for software and is particularly useful in conjunction with the MKS Make software development facility.
Options

-a    sets only the access time.
-c    does not create any files that do not already exist. Normally, touch creates such files.
-m    sets only the modification time.
If you do not specify -a or -m, touch behaves as though you specified both.

To tell touch to use a time other than the current, use one of the following options:

-f agefile    is an obsolete version of the POSIX-compliant -r option.
-r agefile    sets the access and modification times (as indicated by the other options) to     those kept for agefile.
-t time     specifies a particular time using this format:

[[[[cc]yy]MM]dd]hhmm[.ss]

where cc is the optional first 2 digits of the year, yy is the optional last 2 digits of the year, MM is the optional number of the month (01-12), dd is the optional day of the month, hh is the hour in 24 hour format (required), mm is the minutes (required), ss is the optional seconds.

EXAMPLES

touch newfile

sets the modification time of newfile to the present.

touch -t 8001031305 oldfile

sets the modification time of oldfile to 13:05 on January 3, 1980.

touch -r oldfile newfile

sets the modification time of newfile to that of oldfile.

More

More is a command used to read text files. For example, we could do this:

% more poems

The effect of this to let you read the file "poems ". It probably will not fit in one screen, so you need to know how to "turn pages". Here are the basic commands:

q --- quit more
spacebar --- read next page
return key --- read next line
b --- go back one page

For still more information, use the command man more.
To display the file named letter.txt on the screen, the user can type either of the following two commands:

more < letter.txt
type letter.txt | more

The command displays the first screen of information from letter.txt, and then the following prompt appears:

-- More --

When the spacebar is pressed, the next screen of information will be displayed. It is also possible to clear the screen and remove all extra blank lines before displaying the file:

more /c /s < letter.txt
type letter.txt | more /c /s


How to concatenate two files line by line 

I have two text files; each of them contains information by line such like that
file1.txt            file2.txt
----------           ---------
linef11              linef21
linef12              linef22
linef13              linef23

I would like to concatenate theses files lines by lines using a bash script in order to obtain:
fileresult.txt
--------------
linef11     linef21
linef12     linef22
linef13     linef23

1.      paste file1.txt file2.txt > fileresults.txt

2.      awk '
  # store the first file, indexed by col2
  NR==FNR {f1[$2] = $0; next}
  # output only if file1 contains file2's col2
  ($2 in f1) {print f1[$2], $0}
' file1 file2

3.      You can do that with a combination of the sort and join commands. The straightforward approach is
join -j2 <(sort -k2 file1) <(sort -k2 file2)
But that displays slightly differently than you're looking for. It just shows the common join field and then the remaining fields from each file

Comments

Popular posts from this blog

Basic shell scripting part 1

What is $*? Its mainly used for showing up all params. This show all parameter values passed in shell script What does $# stand for? # will return the number of parameters that are passed as the command-line arguments. What does $? Return? $? will return exit status of command .0 if command gets successfully executed ,non-zero if command failed. What are Different types of shells? sh : the oldest shell  csh : C shell  ksh : Korn Shell  bash : bourne again shell  How do you read arguments in a shell program – $1, $2? Shell script accepts parameters in following format…  $1 would be the first command line argument, $2 the second, and so on  $0 is the name of the script or function If your script has more than 9 params then accept in following way…  ${12} : 12th param  ${18} : 18th param What are the different kinds of loops available in shell script ? for, if, while, case What is the difference...

Linux and Maven Commands

Maven mvn -Dmaven.test.skip=true -e clean install mvn clean install mvn clean install -Dmaven.test.skip=true Linux: telnet mq.dev.sum.org  9012 telnet <machine_IP> <port> Sudo su Su - sudo -u dev2adm  -i ps -ef|grep jboss Find a folder Just find directories and skip file names pass the  -type d  option as follows: find   / - type d -name "apt" - ls locate httpdocs Delete latest 3 files: rm -f $(ls -1t ./ | head -3)   working fine ls -d -1tr /path/to/folder/* | head -n -10 | xargs -d '\n' rm -f rm -f $(ls -1t ./ | tail -n +4) netstat -ln | grep '80 ' | grep 'LISTEN' netstat -atnp|grep LISTEN  netstat -ln | grep '99 ' | grep 'LISTEN'  netstat -ln | grep '16'  scp -pr Services-0.0.2-SNAPSHOT.war sbiswas@172.1.8.141:/home/sbiswas tail -f /tmp/Liferay-JBoss.out |grep 'PAGENAME\|tabName' grep 'PAGENAME\|tabName'  for multiple se...

Basic shell scripting part 3

1. What is Shell Scripting ?         Shell scripting, in Linux or Unix,  is programming with the shell using which you can automate your tasks. A shell is the command interpreter which is the interface between the User and the kernel. A shell script allows you to submit a set of commands to the kernel in a batch. In addition, the shell itself is very powerful with many properties on its own, be it for string manipulation or some basic programming stuff.  2. The command "cat file" gives error message "--bash: cat: Command not found". Why?     It is because the PATH variable is corrupt or not set appropriately. And hence the error because the cat command is not available in the directories present PATH variable. 3. How to find the length of a string  in Linux? $ x="welcome" $ echo ${#x} 7 4. What are the different timestamps associated with a file? Modification time:- Refers to the time when the file is last modifie...