Manipulation of file/folder with output of command
I like organising some of my folders in the format of yyyymmdd to keep them in chronological order.
For example, today which is 5th July 2014, I made a folder named 20140705.
I want to manipulate these folders from a shell script, but I cannot find out how to do it without typing the literal name of the folder, such as the following command.
This is not what I want to do because when I make a new folder in the future, I can't use the same script without modifying it.
I know that the date command can create a formatted output of today's date,
which will essentially give me the name of my folder I created today and will also work the same way in the future.
I tried using the output of this command to move today's folder to somedir, for example by using a pipe "|", but it didn't work.
Is there a simple way how to do what I want to do, or am I doing something that cannot be done by shell script?
Last edited by Don Cragun; 07-05-2014 at 09:06 PM..
Reason: Add CODE tags.
Both seems to work, thank you.
Somehow the missing "Code:" is also fixed without me doing anything, thank you for this as well.
Next time I will remember to mention that I am using bash when I ask questions.
Both are working, but you should use Dons suggestion in favour of mjfs: there is a mechanism called "process substitution" in bourne-like shells (Bourne-Shell, bash and ksh, to name the most popular ones). It does the following: take a command, run it in a subshell, then use the output of this command in the current commandline:
This first runs date +'.....', which will display a string, say "20140102". This string now replaces the the command it comes from on the command line, so effectively:
is executed. So far, this is equally the case for both constructs:
The difference is, that the latter is the historic form, which is only supported for backwards compatibility. The modern - and POSIX-standardised - form to write this is the first. The modern form also has some subtle advantages, like the ability to be nested:
This could not be written using backticks at all.
I hope this helps.
bakunin
/PS:
Quote:
Somehow the missing "Code:" is also fixed without me doing anything, thank you for this as well.
This is because Don Cragun edited them into your post, as you can see at the bottom of your post if you scroll up.
I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place.
What I need
The following command is placed at the prompt:
TICLI... (4 Replies)
I ran the following command.
cat abc.c > abc.c
I got message the following message from command cat:
cat: abc.c : input file is same as the output file
How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Hi,
I do have question for un tar a file. I have several 'tar'ed files. For example: SRS.tar.bz2. I was trying to untar them in a linux server using the command:
tar xvjf SRS.tar.bz2
It worked perfectly. but when I open this file in my mac computer all the files are extracted into a... (7 Replies)
Hi all,
I have a command I need to run on a large number of folders. It needs only one input, namely one of the 150 files in the folder (doesn't matter which one):
command filenameThe problem is that the names of the files are random, so I was trying to just get the first file by using list and... (5 Replies)
This has been bothering me for 3 days.
$> hostname
cepsun64amd
And I just want "cepsun",
I would normally do h=`hostname`; ${h%%64*}
But I am looking for a one-liner just for my own knowledge, because if there is a way to do this, I should know it by now.
Anyway, so is this... (2 Replies)
Bash/scripting newbie here - I feel this might be a trivial problem, but I'm not sure how to tackle it. I've got a folder of a year's worth of files, with some random number of files generated every day of the year (but at least one per day). I'm writing a script to automatically grab the file with... (6 Replies)
Hi,
I need to move 1000s of files from one folder to another.
Actually there are 100K+ files.
Source dir : source1
Target dir : target1
Now if try cp or mv commands I am getting an error message : Argument List too long.
I tried to do it by the time the files are created in the source... (6 Replies)
This is the file structure:
DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg
DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg
DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg
DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg
DESKTOP/Root of Photo... (4 Replies)
Hi All,
Please help me out
1) Command to find the disk usage in GB. I know that du -k will give in kilobites.
2) How to find the Biggest file/folder in a given set of files/folders.
Thanks in advance
Regards,
Manas (8 Replies)