I need to copy all files but one from one dircetory to another - wildcard

Total noob question here, but I want to copy every file but file1.txt from 1 directory (i am not in this directory) to another directory using wildcards specificatlly using *
Any help?

Related

Moving files from current directory to one directory below

I am trying to move 2 files from current directory (/base/level1/level2) to one directory below (/base/level1)
Is there any easier command other than mv file1 /base/level1 ? I'm trying to understand if we have some command that move it to a specific level up or down in the current folder structure.
TIA!
My solution to this one is navigating to the path where I want to move the file and run the following command.
cp ./level2/file1 .
or
cp ./file1 ./level2/file1
Please share other solutions as well
Thanks,
AMK
You could use wildcards if the 2 files have something uniquely in common.
ie. mv file*.ext path/to/new/dest/
This will move all files starting with "file" and ending with the extension ".ext" to the destination. Have a look at this and this which will explain wildcards a bit more
You can always use .. for "one directory up".
And you can give more than 2 arguments to mv, the last always being the destination.
So mv file1 file2 .. would move those 2 files a directory up.
Or mv * .. to move all files.

How to list contents of another directory without being in it?

Here is what my directory looks like:
Test ----
|
|----One
|
|----Two
I am attempting to list the contents of Two while still being in One and I am not able to do so.
I have tried this command (as seen in a other post) : "ls Test/" and it says No such file or directory. I have also tried ls Test/Two/ and it still does not work.
If you are in One and you want to list the contents of Two, you should go up to the parent directory using ..:
ls ../Two
../ will place you in the Test directory, from there, you can go to Two with no problem. If you have more depth levels, just add more ../ to go up one directory each time, but mind which is your current directory when running the command.
what does this command provide you in terminal.
ls -al Test //a flag is used for hidden file

Rename many images with names from file

I have a file with a list of names. Let's call it nameFile. For example:
John Doe
John Benjamin
Benjamin Franklin
...
I also have a folder of pictures. The pictures are named like:
pic001.jpg
pic002.jpg
pic003.jpg
...
I want to rename each picture with the corresponding name from the nameFile. Thus, pic001.jpg will become 'John Doe.jpg', pic002.jpg will become 'John Benjamin.jpg', etc.
Is there an easy UNIX command to do this? I know mv can be used to rename, I'm just a bit unsure how to apply it to this situation.
Mostly people do it by writing a simple shell script.
These two links will help you to do it.
Bulk renaming of files in unix
Rename a group of files with one command
The mv is a Unix command that renames one or more files or directories. The original filename or directory name is no longer accessible. Write permission is required on all directories and files being modified.
mv command syntax
You need to use the mv command to rename a file as follows:
mv old-file-name new-file-name
mv file1 file2
mv source target
mv [options] source target

diff multiple originals versus backups

I have a folder with 5 files. I decide I want to do some search and replace on them using sed. Problem is, I need to keep track of the changes. So I make a backup folder "bak" which has all the copes of the original files.
There are now 10 files total. 5 originals and 5 backups.
I would like to run a sed command over the originals and then compare them to the backup to keep track of changes.
would this be as simple as
diff * ./backup_folder/*
The above code doesn't work but it illustrates the concept. Is there a better way to do this?
Perhaps put your backup folder in a different location (i.e. not a subdirectory of your current folder) - maybe in the parent of your current folder. Then a simple:
diff -r ../backup_folder .
or
diff -r /path/to/backup_folder .
should work.
for f in *; do diff "$f" ./backup_folder/"$f"; done

Inserting directory in existing directory structure in unix

I have a directory structure something like :
/etc/home/d1/d2/d3/d4
The last directory d4 contains some files so it is not empty.
But by mistake I forgot to create one more directory in between say d0
So I need to change my directory structure to :
/etc/home/d0/d1/d2/d3/d4
So my question is - is there any way to introduce this new directory in existing path or I have to do all the donkey work? :P
Create a directory under your home directory with name d0. Then use the mv command to move d1 to d0. All directories and files under d1 should get moved to d0 giving you the desired structure.
mkdir /etc/home/d0
mv /etc/home/d1 /etc/home/d0
This is quite different from the single command (when /etc/home/d0 does not exist as a directory):
mv /etc/home/d1 /etc/home/d0
That might be a little confusing. The first creates a directory and moves the hierarchy into it. The second just renames one level in the hierarchy, which was not what you wanted.

Resources