Setting timestamp with Touch
By Eric Downing | Filed in Linux, Scripting, Uncategorized, Utilities | No comments yet.Did you know? You can Set file timestamp using touch command. One way to do this is:
touch -c -t YYMMDDhhmm filename.txt
Did you know? You can Set file timestamp using touch command. One way to do this is:
touch -c -t YYMMDDhhmm filename.txt
Learnable
www.learnable.com
Brought to you by Sitepoint. They have created a site to host their on-line classes and a place for people to create their own as
well.
Udemy
www.udemy.com
Just checking this one out, I found some interesting courses, but many seem to be placeholders for classes to come later.
LiveMind
www.livemind.com
Just read about this one and have not looked thorugh it very much yet.
I regularly have to move scripts between Windows and Linux systems. The line endings from
Windows can make running my scripts on Linux fail. I have been on a few systems where the
dos2unix command was not available, so how do I get rid of the Ctrl-M at the end of the lines?
Command: vi -b <filename>
The -b sets vi into binary mode. This displays the extra control characters. In vi, I remove the
ctrl-Ms.
In vi, I use the following key sequence in command mode:
:%s/<ctrl-v><enter>//g
The ctrl-v tells vi to take the next character and display it as a ctrl char sequence. And hitting the
enter key displays the ctrl-M. The :%s///g is a command to replace the characters in the first // and replace
it with the chars in the second // and the g says to do it to every line.
The other day I had to write a script to change to a working directory and back to the original directory. The problem was they were on different drives on Windows. So I had to find a way to capture the drive letter
and switch back to that drive. When using the following command,
cd F:somedir
you are not moved to the “F:” drive without an explicit “F:” command.
The cd Command on windows will show the current directory location. Using some string manipulation on that and capturing it to a variable allows us to go back to that drive.
REM Capture the current drive letter set ORIGDRIVE=%cd:~0,2% F: REM some other scripting things here REM Return to the original drive letter ORIGDRIVE
The first line captures the current drive letter by specifying the first character with 0 and the ,2 states to pick up the next 2 characters which would hold the “C:” or whatever drive you started on.
I had to write a backup script the other day and used the find command to find the files that were older than a given amount of days.
DAYS_TO_KEEP=7
find /path/to/files* -type f -name *.bak -mtime $DAYS_TO_KEEP -exec rm {} ;
The -name argument uses the escaped asterisk so command completion does not replace it with all the file names.
The -mtime argument takes a number that is the number of days to look at.
The -exec argument takes a command and the {} is replaced with the current file name and the ; is the end of the command.
This is a small part of the power of the find command.
Windows 7 has introduced the concept of a Libary. This is a folder that can contain other folders and is available in the Windows Explorer. So you may have decided that the 4 defaults folders aren’t enough:
So to create a new library:
Each library can contain multiple folders. Now everytime you open the explorer your library will be available to you and you do not have to dig into your file hierarchy to find your most used files.
Suggested Applications:
If you don’t have access to a Unix environment on your windows box, you can still search files with findstr. The findstr command will allow you to search files close to the same way as grep.
findstr /S "search string"
will recursively find your string in the current directory and subdirectories.
There are more options that you can find if you run the following command:
findstr /?
will show you the help message.
So every once in a while I want to see the progress of an upload or backup. So I turn to the watch command in Linux. The watch command gives the user the ability to re-run a command and see the updated output.
The syntax is ‘watch -n
So for watching a file downloads progress you could run the following:
watch -n 30 ls -l filedownloading
This would show the ls output and you could watch the size of the file grow as it is dowload progress.
When attempting to run ant I get the following message: “Unable to locate tools.jar. Expected to find it in C:Program Files (x86)Javajre6libtools.jar”
This had to do with my JAVA_HOME not pointing to a Java JDK.
So if you download a JDK and update your JAVA_HOME environment variable to point to that directory, ant should run happily.
In BASH:
export JAVA_HOME=/path/to/jdk
IN DOS:
set JAVA_HOME=c:PATHtojdk
Every once in awhile I go back and try to figure out how to create a basic ant build.xml file. So I am just placing a sample build.xml here.
The directory structure should be something like
./build.xml
./src/HelloWorld.java
The targets will create the build directory and compile the source and run a test execution of the class.
<project name="HelloWorld" basedir="." default="main"> <target name="clean"> <delete dir="build"/> </target> <target name="compile"> <mkdir dir="build/classes"/> <javac srcdir="src" destdir="build/classes"/> </target> <target name="jar" depends="compile"> <mkdir dir="build/jar"/> <jar destfile="build/jar/HelloWorld.jar" basedir="build/classes"> <manifest> <attribute name="Main-Class" value="HelloWorld"/> </manifest> </jar> </target> <target name="run" depends="jar"> <java jar="build/jar/HelloWorld.jar" fork="true" /> </target> <target name="main" depends="clean,run"/> </project>
Tags: ant