How to change directory in Bash [closed] - bash

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am very new to scripting, can anybody tell how can I switch to directory in bash.
I have tried to do like this
-bash-4.2$ cd /c
and cd c but nothing works!

Check if you have any directories in your current path!
You can check that by ls -lrt which lists the files and directories in your current path.
If there are no directories, create one using mkdir c and then do cd c
Also you can navigate to your previous directory by using cd - and your home directory by doing a cd ~

Related

Recursively move all files in folders with given name to their parent directory [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a document library where all of my files are in folder based on category name but then they are also all in subfolders called 'pdf' as well. Is there a way in bash to scan through all of the directories in the library and move all files in folders named pdf to their parent directory?
This can be done with a find command.
Assuming you have no other folders named pdf, you could run something like this:
cd path_to_library
find . -type d -name pdf -exec bash -c 'cd {}; mv * ..' ';'

symlink mac from outside folder [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Imagine this is my folder structure
filepath\targetpath
filepath\folder1
I can create the symlink when I am inside the targetpath folder
ln -s ..\folder1 folder2
but when I try to create symlink from upper level with below command
ln -s filepath\folder1 filepath\targetpath\folder2
it create shortcut file rather than a symlink to filepath.
How can I create symlink when I am outside of the targetpath folder?
If a symbolic link is not an absolute pathname (begins with /) it is interpreted relative to the directory containing the link, not your cwd when you make the link. So if you do:
ln -s filepath/folder1 filepath/targetpath/folder2
the target of the link is filepath/targetpath/filepath/folder1. You should make the symlink the same way as you did the first time:
ln -s ../folder1 filepath/targetpath/folder2

Unzip files in folders automatically [mac os x] [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a folder on my desktop that has around 2500 folders in it, each folder has multiple files in them that are zipped, I can unzip them by manually clicking on them, is there a way to do this automatically through terminal?
find ./ -name \*.zip -exec unzip {} \; maybe?
you can try the unzip command, but i think it only works with zip/tar files.
http://www.lifewithtech.net/apple/tip-unzip-multiple-files-into-a-single-directory-in-mac-osx/
http://magma.maths.usyd.edu.au/magma/faq/extract
or if you have the app The Unarchiver:
you can use the open command.
cd to your folder and use:
$ open */*.rar
this should extract all rar files in all sub-folders, according to your Unarchiver setup into a new folder or in the same folder.
Hope this helps.

How do I navigate using a symlink? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do I navigate using a symlink?
I created a symlink, let's say 'projects' to my '/Desktop/Work/Projects' folder. So if I type 'ls' in my root directory, I see a bunch of things, the symlink among them. 'cd projects' fails with the error:
-bash: cd: projects: No such file or directory
The symlink is broken. If by 'your' /Desktop/Work/Projects you mean /home/youruser/Desktop/Work/Projects, then that's the path you should symlink to:
ln -s "/home/youruser/Desktop/Work/Projects" "/home/youruser/projects"

mkdir -p cannot create directory `/DirName': Permission denied [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm trying to create a directory in a shell script:
mkdir -p DirName
but I always get the same error:
cannot create directory `/DirName': Permission denied
If I run the same command directly from the shell instead of using the scripts, that works perfectly.
any idea?
Thank you! :)
If you're going to use the -p option, you need to specify the full path
mkdir -p /some/path/here/DirName
I suggest listing the full path (If you plan on your shell script to change locations).
If your shell script isn't going to change locations (you're not going to move it somewhere else later), I'd use:
mkdir ./DirName
These should all behave similarly to you creating the directory in the shell.
You are trying to create a directory in the root of the filesystem (/DirName) instead of in the current directory (Dirname or ./Dirname). You don't have access to write to the root.

Resources