How to move all files including hidden files into parent directory via *
You can find a comprehensive set of solutions on this in UNIX & Linux's answer to How do you move all files (including hidden) from one directory to another?. It shows solutions in Bash, zsh, ksh93, standard (POSIX) sh, etc.
You can use these two commands together:
mv /path/subfolder/* /path/ # your current approach
mv /path/subfolder/.* /path/ # this one for hidden files
Or all together (thanks pfnuesel):
mv /path/subfolder/{.,}* /path/
Which expands to:
mv /path/subfolder/* /path/subfolder/.* /path/
(example: echo a{.,}b
expands to a.b ab
)
Note this will show a couple of warnings:
mv: cannot move ‘/path/subfolder/.’ to /path/.’: Device or resource busy
mv: cannot remove /path/subfolder/..’: Is a directory
Just ignore them: this happens because /path/subfolder/{.,}*
also expands to /path/subfolder/.
and /path/subfolder/..
, which are the directory and the parent directory (See What do “.” and “..” mean when in a folder?).
If you want to just copy, you can use a mere:
cp -r /path/subfolder/. /path/
# ^
# note the dot!
This will copy all files, both normal and hidden ones, since /path/subfolder/.
expands to "everything from this directory" (Source: How to copy with cp to include hidden files and hidden directories and their contents?)
Move all files/directories/hidden files into directory but ignore destination directory?
What you're doing already actually works fine: you do get an error about moving something onto itself, but that error is harmless and doesn't stop the rest of it from working.
If you really don't like that, you can do this:
find . -maxdepth 1 ! -name backup -execdir mv {} backup +
Finding a filetype in current directory and subdirectory, including hidden files. (Homework)
It's not very clear what you are trying to achieve.
As lurker said in the comments cut -d. -f1
will make any line starting with a .
be a blank line.
From your code, the closest I could think of is
find $directory -type f -iname '*.gif' | rev | cut -d/ -f1 | cut -d. -f2,3 | rev | sort -f
Giving you all gifs, hidden or not, without path or extension.
Example
user@host /tmp % ls -aR
.:
. .. subdirectory .test.gif test.gif
./subdirectory:
. .. .sub.gif sub.gif
user@host /tmp % find . -type f -iname '*.gif' | rev | cut -d/ -f1 | cut -d. -f2,3 | rev | sort -f
sub
.sub
test
.test
Searching files older than a specific time and move them into a specific folder
This one-liner can find the files in the directory passed as the first argument source directory
, which is older than the second argument age
and move the filtered files to the third argument destination directory
#!/bin/bash
find /"$1" -maxdepth 1 -mtime +"$2" -type f -exec mv "{}" "$3" \;
Related Topics
Serial Port Doesn't Work Properly After Reboot, Unless I Execute Minicom
Black Color Showing on Cmy Channels When Converted to Cmyk Using Ghostscript
Groovy Process Not Working with Linux Shell (Grep and Awk and Ps)
Minicom Black Background Color Is Not Respected
Every Command Is Returning 'Bash: <Command>: Command Not Found...'
No Such File or Directory Find Command on Linux
How to Preserve Command Line Spaces in a Linux Application
How to Make Find and Printf Works in Bash Script
For Loop in Bash Simply Prints N Times the Command Instead of Reiterating
Bash Variable Assignment Not Working Expected
I Want to Remove Multiple Line of Text on Linux
How to Obtain the Mdns.Service File Needed for Building Mdns in Yocto
Python Module Import Error for One User But Not the Other
Grabbing Specific Sections of Text from a String
What's the Reason Docker Ubuntu Official Image Would Exit Immediately When You Run/Start It