So here I've created, or at least tried to create an alias for a command that accepts a command-line argument, makes a new directory with that name, and goes to it.  alias newfolder='mkdir $2 ; cd "$(history | tail -2 | awk '\''NR == 1'\'' | awk '\''{print $3}'\'')"'   The alias created successfully, but when I want to run the command with a command-line argument, I get this error message.  username:~/workspace (master) $ newfolder a mkdir: missing operand Try 'mkdir --help' for more information. bash: cd: newfolder='mkdir: No such file or directory
26088
I find myself repeating a lot of:  mkdir longtitleproject cd longtitleproject   Is there a way of doing it in one line without repeating the directory name? I'm on bash here.
2796
Ok, I have a bunch of files starting with a dash, -. Which is not so good... and I want to rename them. In my particular case I would just like to put a character in front of them.  I found the following line that should work, but because of it dash it doesn't:  for file in -N*.ext; do mv $file x$file; done   If I put an echo in front of the mv I get a bunch of  mv -N1.ext x-f1.ext mv -N2.ext x-f2.ext   Which is correct, except of course it will think the first filename is options. So when I remove the echo and run it I just get a bunch of  mv: illegal option -- N   I have tried to change it to  for file in -N*.ext; do mv "$file" "x$file"; done   but the quotes are just ignored it seems. Tried to use single quotes, but then the variable wasn't expanded... What do I do here?  Update: I have now also tried to quote the quotes. Like this:  for file in -N*.ext; do mv '"'$file'"' '"'x$file'"'; done   And when I echo that, it looks correct, but when I actually run it I just get  mv: rename "-N1.ext" to "x-n1.ext":: No such file or directory   I have just no clue how to do this now... sigh
79466
I can type:  dirname ~/home/blah/file.zip   for instance, and this works fine alone, but when I use this syntax as the parameter for some command it always reads 'dirname' as the desired directory. i.e.:  cd dirname ~/home/blah/file.zip bash: cd: dirname: No such file or directory   Basically, how do I get 'dirname file' to be read as one entity?
72629
Let's say the directory ~/this_dir doesn't exist.  I need to be able to run touch ~/this_dir/new.txt to create new.txt in ~/this_dir.  Is there a simple way to make touch also create the directory?  Or an alternative command which would achieve the same thing?  Thanks
66174
This  gave me cd - as shorthand to change to my previous directory in Bash. It does have a major problem: it prints the directory it changes to, wasting my screen space, as that directory is then repeated in the prompt on the next line.  I know I can do cd $OLDPWD, also mentioned in that answer, and cd - &gt;/dev/null but that is much more typing.   In the bash man page it says:     ... or if - is the first argument, and the directory change is successful, the absolute path name of the  new  working  directory  is written to the standard output.   How can I make - not to be the first argument? By using any of the cd optional arguments? Any other way to suppress the echo or minimise typing without the need for defining functions/aliases on every machine I work with?
94744
I'm trying to find where a specific alias has been declared. I've searched all the usual places I know to look for aliases:   ~/.bashrc ~/.bash_profile /etc/bashrc /etc/profile   With no luck.  I know it's an alias because when I do which COMMAND, I get:  alias COMMAND='/path/to/command'     /path/to/command   Is there a way to find what file declares an alias only knowing the alias name?
5412
Running a kornshell and trying to traverse a directory tree. Want to cd to a sub-directory named as follows:   -3ab_&amp;_-3dc.img   My question is HOW do I need to escape the ampersand in this name? I've tried different combinations of double-quotes and backslashes without success.
119503
I want to create this folder: $HOME/a/b/c/d while $HOME/a has not yet been created! Is it possible with one line in Terminal?
36164
According to  and my own understanding, the tilde expands to the home directory:  $ echo ~ /home/braiam   Now, whenever I want the shell expansion to work, i. e. using variable names such $FOO, and do not break due unexpected characters, such spaces, etc. one should use double quotes ":  $ FOO="some string with spaces" $ BAR="echo $FOO" $ echo $BAR echo some string with spaces   Why doesn't this expansion works with the tilde?  $ echo ~/some/path /home/braiam/some/path $ echo "~/some/path" ~/some/path
58849
I have an executable that I use often:  /dir1/dir2/dir3/dir4/executable argv[1] argv[2] argv[3]   I know that I can set an alias for the executable:  alias myexecutable = '/dir1/dir2/dir3/dir4/executable'   and then call it  myexecutable argv[1] argv[2] argv[3]   However, I'd like to call it like this  myexecutable argv[1]   because the first argument is the only one that ever changes. The second and third one should always be passed as the same every time.
112544
What's wrong with the commands below?  $ var1="~/Music/$(date +%d%m%y)" $ echo "$var1" ~/Music/240118 $ mkdir "$var1" mkdir: cannot create directory ‘~/Music/240118’: No such file or directory   However  $ mkdir ~/Music/240118   works.  Never thought I would ask such questions after years of using bash...
53787
I want to set an alias to start nedit together with command line option -noautosave (due to text files up to 500MB). What seemed to be easy:  alias nn="nedit -noautosave $1 &amp;"   just raises some error "Permission denied" of a different file and another error about unexpected EOF while looking for matching "'" and "unexpected end of file".  One solution I found after a Google Search would be to check the quotes, but I can't see any possible errors with them.  I also tried declaring a function:  function nn () { nedit -noautosave $1 &amp;}   which also failed with same errors.
72835
is there any way (what is the easiest way in bash) to combine the following:  mkdir foo cd foo   The manpage for mkdir does not describe anything like that, maybe there is a fancy version of mkdir? I know that cd has to be shell builtin, so the same would be true for the fancy mkdir...  Aliasing?
83915
I'd like to write a bash scipt that would change to target directory and list the contents of new directory, all in one step. It would replace the two commands I constantly use consecutively:   cd ./some_directory ls -al   After executing the script, my current directory would change, and ls -al would show the dir list.   cdl ./some_directory   Is this possible?
40712
Edit: This is a duplicate of .  I don't have the reputation to close this question as duplicate.  I'm not referring to ~ as in the home directory but rather this:  $ ls ~foo/bar /some/mount/point/foo/bar   However if I attempt it with a different mount point, e.g.:  $ mount | ag "/dev " devfs on /dev (devfs, local, nobrowse) $ ls /dev/stdin /dev/stdin $ ls ~stdin zsh: no such user or named directory: stdin .  # bash has a similar error message:  ls: ~stdin: No such file or directory   What is the ~ called in this context?  How does it work?  Edit: More information based on some of the comments below:   I can attest that foo is not a username on my system. When attempting to autocomplete ls -lah ~ not all options are shown.  i.e. I'm able to cd ~qux, when qux doesn't show up in the autocomplete.  Again qux is not a user in my system. If it matters /some/mount/point is a network share. All of the details suggest some named path muckery, a Z shell feature of pathname expansion, but this works in bash as well, which apparently doesn't support things like the Z shell's named paths.
66342
When I create  alias wd='ps -ef | grep java | awk {'print $2 " " $9'} | egrep "(A|B|C|D)"'   or  function wd () {     ps -ef | grep java | awk '{print $2}' ... }   in my .bashrc file, I get errors.  Interestingly, if I source my .bashrc file with the function, it 'compiles', but when executing, gives me:   context is      &gt;&gt;&gt; \ &lt;&lt;&lt; {\print     missing }   Can someone help me with this, and also answer when its better to put something in a function versus in an alias?
8187
Writing my first script so I'm sure this is a basic question, but can someone please explain to me why I can:  cd ~ cd bin cd ~/bin cd 'bin'   But not  cd '~' cd '~/bin'   I need to cd to a directory path with a space in one of the directory names, so I need the quotes (it's Windows Program Files under wine). I can get around it with two cd commands, but why can't I put ~ in quotes?  If I type cd '~' (or cd "~") I get:  bash: cd: ~: No such file or directory