Tag Info

Hot answers tagged

6

To backup directory dir into a file named after today's date and time: name=$(date '+ht-%F-%H-%M-%S.tgz') tar -czf "$name" dir You may eventually want to use a program such as rsnapshot, dirvish, or one of their competitors. These programs automate the process and also, via the use of hardlinks, save on disk space if you are keeping multiple backups.


5

To delete all files ending in .jpg (case-insensitive) except for files with sample in the file name (case-insensitive: find . ! -iname '*sample*' -iname '*.jpg' -delete This recurses through all directories in the tree starting at the current directory. How it works: . This specifies that we start with the current directory. ! -iname '*sample*' ...


5

You defined a bash function. So you are already in a bash shell when invoking that function. So that function could then simply look like: clock(){ echo "do something" $@ } That function can be invoked with bash builtins, special reserved words, commands, other defined functions: An alias: $ clock type ls do something ls is aliased to `ls ...


3

I suspect "ru" isn't a valid locale. Try the command lang=ru locale and see if there are any error messages. On my system, "ru" is an invalid locale and "ru_RU" is in iso8859-5; you need ru_RU.UTF-8 for it to work in utf-8. $ LANG=ru locale locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default ...


3

without the -A, ps will only print the processes belonging to the current session. Think of it like "absolutely everything". On a related note -a does the same thing, but restricting it to the session-owner (username).


3

By default, only STDOUT is redirected and/or piped. What you want is to leave STDOUT alone, and have whatever is passed via STDIN redirected. If editing the_command is an option, you could make sure that the question is output to STDERR instead (that should dump it to screen regardless of any redirects), and then have it echo whatever the user types back to ...


2

In bash (or ksh), you can use the indirection syntax ${!var} to reference the variable whose name is the value of $var. It has to be the complete name, so you have to do it like this: for j in {1..2}; do # This could have been declare instead of export if you don't need # to export the variable. export var${j}=$j varname=var$j echo ...


2

This is not possible with your current function, as soon as you background it with & it takes a copy of the process stack and leaves. There is no way for the changes to your stack to propagate to the job's copy unless you explicitly build that functionality, and it's similarly impossible to get changes to the function's stack into your current stack. ...


2

$ cat input.txt banana coffee кофе Банан Apple Coffee арбуз apple Banana Кофе банан Арбуз $ export LC_ALL=en_US.UTF-8 && sort --ignore-case input.txt apple Apple banana Banana coffee Coffee арбуз Арбуз банан Банан кофе Кофе


2

If the wrapper needs to insert code before the given command, an alias would work as they are expanded at a very early stage: alias clock="do this; do that;" Aliases are almost literally inserted in place of the aliased word, so the trailing ; is important – it makes clock time foo expand to do this; do that; time foo. You can abuse this to create magic ...


2

The only way to launch a shell builtin or shell keyword is to launch a new shell because exec “replaces the shell with the given command”. I thought that this was an interesting problem but shouldn’t be too hard to solve. However, getting the quoting right took over almost an hour of trial and error (Bash is great but I’m not a fan of the quoting). You ...


1

If you are behind a firewall please try this before: git config --global url."https://".insteadOf git://


1

If you don't simply want to use mkdir -p and then a cp, then you may as well create a fairly robust function to copy it wall always be the same folder to the directory name given by dirnm as the first argument (in the current working directory if no second argument given) or to /destpath/dirnm if a path representing destpath is given in argument as the ...


1

In bash, you can use shopt -s extglob to enable negative matching: rm !(*[Ss]ample*).jpg To match subfolders too, turn on shopt -s globstar and use the double star: rm **/!(*[Ss]ample*).jpg


1

There are usually 2 important output pipes: STDOUT (for regular output) and STDERR (for error messages). The problem here is, that the "regular" output of the command and the text of the prompt are both written to STDOUT, so they are always put into the same location. When you use your redirection, it just takes the whole STDOUT, including the prompt. If ...


1

Your command works and properly redirects the output to the file abc.txt. The question is how is your script asking the input data and how are you running the script? Let we see with two examples: # Script_1.sh # 1 echo Please, enter your firstname and lastname # 2 read FN LN # 3 ...


1

But I want to know if I should be ignoring .bash_profile and those other files, and putting everything into the .zshrc file? A lot of instructions online for installation or system set-up stuff have me adding stuff to .bash_rc, etc. I assume if I’m into using zsh, I should be putting that stuff in .zshrc? This webpage explains the differences ...



Only top voted, non community-wiki answers of a minimum length are eligible