Why not "mv -r" in Linux bash? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
Well, I know you have to use -r with cp and rm when dealing with directories. It makes this job recursively (meaning it coping and removing all starting with things inside).
But why you dont do "mv -r" when moving / renaming directories?

Directories are just collections of pointers to locations of files on the filesystem. When you move a directory you are updating the file pointers of the new and old parents to contain/remove the one you moved. Thus, child file pointers inside do not require recursive action as none of the pointer locations have actually changed for them.
EDIT: I've just found a much more detailed answer on Unix & Linux StackExchange that will help explain this further.
https://unix.stackexchange.com/questions/46066/why-unix-mv-program-doesnt-need-r-recursive-option-for-directories-but-cp-do

For every move, new location is needed.
If one wants to move all files under directory alongwith the directory, just move the directory which is recursive.

Related

Is there an easy way to deal with files with long filenames and long directory names in linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Suppose I have a directory on my disk that has the name: photos_with_my_friend_John_from_first_semester_of_my_graduation_year
Now each time I want to enter this directory I must write the following command:
cd photos_with_my_friend_John_from_first_semester_of_my_graduation_year
I am new to linux and for me it is very boring to write this whole name each time I want to deal with this directory or any other directory or file that has such a long name. So is there an alternative easy way to do this?
Most shells offer tab completion: You simply type cd phot and hit Tab, and it'll insert the rest for you (assuming the prefix is unique).
How about using wildcards? Say photos*John*graduation etc.?
You can create a symbolic link for ease of access:
ln -s long_file_name short_file_name
then you can use short_file_name as you wish.

Keep two directories synced in ubuntu in real time [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
My intention is to keep two directories (say dir1 & dir2) synced. So that whenever there is a change in the content of the dir1 (can be addition or deletion of new file or directory or modifying the content of a file in the directory) then the change should be propagated to dir2 and vice versa.
The naive way I can think of doing this is to run rsync periodically via cron in both the machines. But there are fallacies in this approach:-
It might happen that the previous rsysnc is not complete and the cron executed rsync once more while the previous rysnc is still going on.
A new file is added in dir1 and before rsync ran on dir2 rsync on dir1 ran then newly added file might be deleted from dir1 since it is not present in dir2
Also this is not real time.
Can some suggest some better way of doing this?
It strongly depends on the purpose. 'Realtime' is probably not the term you are looking for.
Take a look at https://www.gluster.org/ (Replicated Mode) for a synchronous replication via network.

What's the order of deletion when I do "rm -rf data"? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I accidentally did a rm -rf data in a huge directory. I exited immediately.
The directory has a simple structure (they are all date-keyed sub-directories, like 2015/07/06) but the directory is huge and I don't want to regenerate the whole thing. If I knew how rm removed the files, I could find and regenerate just the missing ones.
How does rm -rf go about deleting files?
rm performs a depth-first search, walking the results of the xfts_open call.
FTS is the standard means by which files are traversed in all the Linux tools. You can write your own fts consumer, or trust the output from find, since it also uses xfts_open.
find . will list the files that exist. You can then use your knowledge of the expected structure to reverse the list that are missing.
Alternatively, you can use debugfs to help you get at the files.

Unix shell directory history [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
The history feature is great for remembering commands. Is there a feature that remembers recent directories?
I'd like to be able to search through a history of directories - it'd be even better if it was possible to bookmark and name them, as you can do in a browser.
You can do cd -1 to get back to the previous directory, cd -2 to get to the former etc.. You can also refer to them using ~1, like cp ~1/README.md ~2/
For a more advanced use, you can use the dirs builtin. You can also use pushd and popd to stack up directories and get back to them later on, pretty useful in scripts.
cf the directory stack
Zsh has the same facility, the dirstack. And with zsh, you can have more fun with directory bookmarks,
Finally, there's even a crazy guy who implemented a GUI for listing the dirstack. Not sure how useful that can be, but it's definitely crazy enough to be referred :-)
HTH
To save directories and keep a historial, you can try pushd and popd from bash

linux: which is the right way to copy folder? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I want to copy folder ajax_search, path: /home/thejobco/public_html/JCCore/ajax_search/ to be inside this foler:/home/thejobco/public_html/demo/typo3conf/ext/, should I run command this way:
cp -r /home/thejobco/public_html/JCCore/ajax_search/ /home/thejobco/public_html/demo/typo3conf/ext/
or
cp -r /home/thejobco/public_html/JCCore/ajax_search/ /home/thejobco/public_html/demo/typo3conf/ext
I am familiar with window, but not unix/linux, I put / after ajax_search, I know this way ajax_search/, shows ajax_search is a folder, but i do not know should i put / after ext or not? can anyone explain to me which is the right way to copy folder? thanks
With cp, if the destination directory already exists and you do not use a trailing slash on the source-dir, then you are actually putting a copy of source-dir inside dest-dir; this can be a problem when you forgot that the destination directory already exists.
You should include the trailing slash, to make it obvious to cp that you are trying to copy a directory name to a new directory name, and not copy the directory into an existing one, if it exists.

Resources