About basic commands in bash (cp, cd,..) [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 8 years ago.
Improve this question
I am trying to learn basic commands in the terminal. I have a couple of quick questions. I know that to make a file and place it in a specific folder, one needs to create the directory and then use touch to create an empty file and place it there by mv:
mkdir folder/sub
touch file.txt
mv file.txt folder/sub
Could we somehow chain these things together and use touch to create a file and place it in a specific directory in just one line?
and then if I am in a sub-directory, in order to get back from there (say: folder/sub) to my home, either of these three commands would work (cd, cd -, cd ..) I am not sure I get the differences among the three. I get that cd .. takes you back one step up but the other two seem to work exactly the same.
and let's say I have already a text file in my home directory named file.txt. If I write this in shell it overrides that existing file:
cp folder/sub/file.txt ~/
How would I go about this if I wanted to keep both files?

You can pass a relative or absolute path in any folder to and command, including touch (although the folder must exist):
touch folder/sub.file.txt
cd - switches to the folder you were last in (like a "Back" button)
. means the current directory
.. means the parent directory

Related

ls command tells me there's no such file or directory when the file does exist? [closed]

Closed. This question is not about programming or software development. 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 months ago.
Improve this question
when i enter
cd prctcfldr
it tells me that i'm in the directory
~/prctcfldr$
but when i enter
ls prctcfldr
it tells me that there is no such file or directory
ls: cannot access 'prctcfldr': No such file or directory
this is happening with all my other directories including Desktop, which is really confusing since this error has not happened with my directories before, and i havent made any changes to them between now and the last time. i know the folder exists because i can see it and open it from the actual homescreen. i'm new to the linux command line and ive been looking for solutions to this error for a little while.
does anybody have a solution?
cd ..
This command moves above one directory and then you can ls <folder name>
Since you are already inside the folder when you ls again the folder name, it'll show directory does not exist.

Why rsync failed to copy all files? [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 4 years ago.
Improve this question
I tried to copy 17171 files, but whatever parameters I use, it always copied 17160 which 11 lost.
But same command for another directory, copied accurately. (16545 files).
I also tried use cp, but also lost 11 files.
When I check the folder with finder, it should be 17171 files there...
rsync -arvz src dst
cp src dst
Above is the command I've tried
There can be a number of issues at play:
One of the more common issues is that the target filename is illegal on the remote system, for example trying to copy a file with a colon : in the filename from UNIX to Windows.
There may also be permission issues reading the files that are not copied, check the permissions here.
Finally, you could try zipping (or taring) the bunch of files into a single file, and transfer just that instead. Typically you'll see the problem when unpacking that file on the remote system.
EDIT: Another thought - are the files that did not copy really-really large, too large to store remotely?
If you rsync with the -P option, it should only re-transfer files that were not copied. It will also print progress, that should give you a better idea of what's not copying.

Symbolic Link Edits and differences to hard link [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 4 years ago.
Improve this question
I just created a symlink to a directory using:
ln -s /path/to/real/ link
1 - If I then cd into link/ will any changes I make in there be reflected in the original directory?
2 - Additionally, the source directory is a git repo, so can I do the git commands from the symlink'ed directory?
3 - These answers and any general explanation about the differences between sym/hard links (or ln in general) would rock.
Thank you!
Symbolic links work just like another name for the original directory. They are different from hard links because if you replace the original file with a new one of the same name, the symbolic link points to the new file. A hard link would still be linked to the original file, no matter what name it had.
A symbolic link can "dangle" which means that it's target is no longer there. A hard link cannot.
A directory cannot be hard-linked. In the past that was allowed but it creates the possibility of directory loops, and this is a bad thing.
Yes if you cd symlink you can do anything that you want, just as if you were in the actual directory, because you are in the actual directory. Your shell, depending on its configuration settings, will allow you to think you're in the symlink named directory, but all of the operating system functions will return the actual directory names.
When you do cd link/, your current directory becomes /path/to/real and any changes you make in the directory are in 'the real directory'.
Beware of cd -L vs cd -P — see POSIX on cd — and similarly with pwd.

How to hide a files from Filezilla (or from directory search) [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 4 years ago.
Improve this question
What are the ways that I can hide files and folders from any directory search ?
For example :
(What I will do)
Access the remote server through putty
Then will show the files inside the folder
(What I WANT to do)
To hide the files inside those folder
(What I tried to do)
I tried to changed the file permission via FileZilla (Doesn't work)
I tried to create a new filter rules via FileZilla (It works but only hides from filezilla)
Thank you for help!
What are the ways that I can hide files and folders from any directory search ?
There is no such thing as "hiding a file".
In Windows you can set the hidden or system flag, but this doesn't actually hide the file, it's just a filter for directory search operations that choose to ignore hidden or system files.
They would be invisible to dir but completely visible to dir /ash
In *nix, files that start with a "." are not shown by default but that's also just a convention. They're not actually hidden and are just suppressed by file operations that don't want to show "dot" files.
ls would not show .mysecretfile but ls -la would show it.

Copy multiple files from one directory to another from Linux shell [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 several files from one folder to another. How do I do it from the shell command prompt?
Consider that folder1 contains ten files (e.g. file1, file2, abc, xyz,
etc.). I am currently doing the following in order to copy two files from one folder to another:
cp /home/ankur/folder/file1 /home/ankur/folder/file2 /home/ankur/dest
Typing the full path into the command line for both the files is annoying.
What comes to my mind is regex, but I don't quite know how to do it.
Any help will reduce my RSI ;-)
I guess you are looking for brace expansion:
cp /home/ankur/folder/{file1,file2} /home/ankur/dest
take a look here, it would be helpful for you if you want to handle multiple files once :
http://www.tldp.org/LDP/abs/html/globbingref.html
tab completion with zsh...
Use wildcards:
cp /home/ankur/folder/* /home/ankur/dest
If you don't want to copy all the files, you can use braces to select files:
cp /home/ankur/folder/{file{1,2},xyz,abc} /home/ankur/dest
This will copy file1, file2, xyz, and abc.
You should read the sections of the bash man page on Brace Expansion and Pathname Expansion for all the ways you can simplify this.
Another thing you can do is cd /home/ankur/folder. Then you can type just the filenames rather than the full pathnames, and you can use filename completion by typing Tab.
You can use brace expansion in bash:
cp /home/ankur/folder/{file1,abc,xyz} /path/to/target
Try this simpler one,
cp /home/ankur/folder/file{1,2} /home/ankur/dest
If you want to copy all the 10 files then run this command,
cp ~/Desktop/{xyz,file{1,2},next,files,which,are,not,similer} foo-bar

Resources