2012-09-19
2012-09-18
Bash Shell: Check if a file exists, and has a size larger than 0
To check, whether a file exists and has a file size larger than 0 use this expression:
if [ -s someFile.txt ]
then
...
fi
if [ -s someFile.txt ]
then
...
fi
Bash Shell: Check if a file exists
To check, whether a file exists use this expression:
First, create the file thisFileExists.txt:
touch thisFileExists.txt
Now, check if it exists:
if [ -f thisFileExists.txt ]
then
echo It is there
fi
This is what it looks like in terminal:
First, create the file thisFileExists.txt:
touch thisFileExists.txt
Now, check if it exists:
if [ -f thisFileExists.txt ]
then
echo It is there
fi
This is what it looks like in terminal:
Labels:
bash,
bash shell,
condition,
file,
file operations,
if,
shell,
shell script
Bash Shell: Repeat a command every x seconds, e.g. to update list of files
When running a command that changes/creates files and takes a while, one might be interested in seeing how progress is going.
For this the "watch" command can be useful:
watch -n 2 ls *file
This will print the output of "ls *file" every 2 seconds.
watch -n 2 -d ls *file
Adding -d will highlight all the changes in comparison to the last time the command was performed
For this the "watch" command can be useful:
watch -n 2 ls *file
This will print the output of "ls *file" every 2 seconds.
watch -n 2 -d ls *file
Adding -d will highlight all the changes in comparison to the last time the command was performed
Subscribe to:
Posts (Atom)