Tag Info

Hot answers tagged

30

You can bypass aliases by the following methods: the full pathname of the command: /bin/ls command substitution: $(which ls) the command builtin: command ls double quotation marks: "ls" single quotation marks: 'ls' a backslash character: \ls


12

You can't use file1 > file2 to copy file1's contents to file2 because there's no command there. You have to issue some command. Redirections apply to (1) a command you run or (2) the shell as a whole (if applied to the exec builtin). But they work by changing the source or target of actions that perform input-ouptut operations--that is, that read from ...


10

From man bash: DEFINITIONS The following definitions are used throughout the rest of this document. blank A space or tab. word A sequence of characters considered as a single unit by the shell. Also known as a token. name A word consisting only of alphanumeric characters and underscores, and ...


9

You can do it without a loop: mkdir -p Week{1..15}/Assignments


9

/ and // are pointing to same directory. See repeated slahes in a path are equivalent to a single slash This behavior is mandated by POSIX and most applications follow suit. The exception is that “a pathname that begins with two successive slashes may be interpreted in an implementation-defined manner”. What you're seeing is not, in fact, Linux ...


8

because _ is part of the variable name in your echo _$now_ use echo \_$now\_ instead. Also you can use that just in a linear command: echo _$(date)_


8

You can redirect the content of text1.txt using the cat command: ~# cat /root/Documents/text1.txt > /root/Documents/text2.txt Note: you can use cat to also create new binary files, e.g: ~# cat mypic.jpg > my_new_pic.jpg


7

You can disable an alias using \ in front of command. So to run the original ls command you need to run it using \ls For example First creating alias of ls command. [guru@guru-Aspire-5738 /]$ alias ls='ls -l' [guru@guru-Aspire-5738 /]$ ls total 96 drwxr-xr-x 2 root root 4096 Sep 3 18:31 bin drwxr-xr-x 5 root root 4096 Sep 17 02:51 boot drwxr-xr-x ...


6

This is explained very nicely in the relevant section of the bash manual. Briefly, anything within single quotes is interpreted literally. So, for example: $ echo '$SHELL' $SHELL $ echo '{1..3}' {1..3} Compare that to the unquoted versions: $ echo $SHELL /bin/bash $ echo {1..3} 1 2 3 Double quotes allow variable expansion (also history expansion and ...


6

Suspend alias expansion You could also disable alias expansion for all aliases temporarily, without deleting them: $ shopt -u expand_aliases $ command -v ls /bin/ls To enable them: shopt -s expand_aliases $ command -v ls alias ls='ls --color=auto' Note that alias expansion is disabled by default in scripts, but set by default in interactive shells.


5

You could add command before the aliased command, e.g. command ls Or run the original executable by combining which which ls It will return "/bin/ls", therefore with `which ls` you could execute it directly.


4

bash offers the Ctrl+Alt+e shortcut (from the bash man page): shell-expand-line (M-C-e) Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions. Examples: ls Ctrl+Alt+e ls -aF --color !268 Ctrl+Alt+e ps -aef $PATH Ctrl+Alt+e ...


4

you can use script in following manner #!/bin/bash clear for var in "$@" do shred -n 3 -zvfu "$var" done Or A shorter version #!/bin/bash clear for var do shred -n 3 -zvfu "$var" done Run your script followed by the file name you want to shred. You can use multiple file separated by space.


4

A few ways: Kill any instance of the script: pkill -f start.sh This will kill any process with start.sh in its command line, using pkill. Kill a specific instance of the script: Modify the script to save its PID somewhere: #! /bin/bash echo $$ >> /tmp/start_sh.pid end=... And tell stop.sh to kill the process with the PID there: #! /bin/bash ...


4

You can run gnome-terminal disabling the factory mode. This will prevent it from starting a terminal connected to an existing terminal, so that the command does not return immediately: gnome-terminal --disable-factory echo Done. # Will only run after the terminal opened above has been closed From man gnome-terminal: --disable-factory Do not ...


4

Bear with me for a moment, this requires a bit of explaining. First of, why is output of _ $(date) _ is _ Mon Sep 22 03:30:34 MDT 2014 _ ? Because this literally tells echo to output _ first then output $(date) then _ . Spaces separate the variables for echo. Now try echo _$(date), note no space between _ and $(date). In this case output will be _Mon Sep ...


3

If you want, you can execute bash script by itself with adding your script in startup applications. type "Startup Applications" in dash and open it. click "Add" button and browse your script location then add bash to begging of the path and put a name then click Save. And then how to make itself execute? just add chmod +x /path/to/myscript.sh at the ...


3

You can also run the command from its original location /bin/ls instead of ls


3

I have an update.sh file, which is run every night I read that as "I'm launching this via cron". A very common issue people have with cron is that they make expectations about the environment the script runs in. They assume the script will run in their home directory. That's exactly what you're doing. All your sed commands use relative paths so they ...


3

There are a few ways - try using this loop: for i in {1..15}; do mkdir Week$i/Assignments; done You could also cheat at the Week folders - use this: for i in {1..15}; do mkdir Week$i; done Just for future reference - if you need to do something similar.


2

Bash uses special environment variables for handling arguments/parameters $0 : the scriptname itself $# : Total number of arguments $1 : first argument $2 : second argument and so on #!/usr/bin/env bash echo name of script is $0 echo first argument is $1 echo second argument is $2 echo number of arguments is $# The output of this program will ...


2

history n prints only n lines of the history. For example: $ history 4 2000 type history 2001 help 2002 help history 2003 history 4 $ So we can make an alias in your .bashrc: alias h="history 100" From help history: history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...] Display or manipulate the ...


2

Tab Completion If you only have one file in /usr/local/bin whose name starts with Katy, you can simply type sudo rm /usr/local/bin/Katy without pressing Enter yet. Then press Tab to complete the command to: sudo rm Katy\ Perry\ -\ Dark\ Horse\ \(Official\)\ ft.\ Juicy\ J-0KSOMA3QBU0.mp4.part (And then press Enter to run it.) This quotes each ...


2

This is how you do it straight with the shell: zip -r folder{.zip,}


1

Running sudo chmod -R 777 /etc/ was a stupid thing to do. You probably recognise that now but you've set every file in /etc/ and its subdirectories to be readable, writable and executable by any account on the system. The files in there are mostly root owned and have permissions set for security... To stop just anybody or anything overwriting, deleting or ...


1

Answer inspired by edit to OP. Please don't kill me... Order in scripting is pretty important. First off, you need to put the function first. You also need to put the trap before the loop. Something like this should work well: #!/bin/bash function finish() { echo "bye bye!" } trap finish SIGINT for number in $(seq 10); do echo "TODO: ...


1

To expand on @SylvainPineau's answer, the reason you can't do /root/Documents/text1.txt > /root/Documents/text2.txt is that the thing separate from the redirect operator and the file after it has to be a command. When you execute /root/Documents/text1.txt > /root/Documents/text2.txt you are telling the shell to execute /root/Documents/text1.txt, which ...


1

Please try the following command, it should start both jobs: gnome-terminal --tab -e " sh -c ' (gedit /media/ubuntuman/Onces\ And\ for\ Al/scripts/faceBook &) ; sudo cpulimit -e ubuntu-tweak -l 80;'" Parentheses denote a subshell in bash. To quote the man page: (list) list is executed in a subshell environment (see COMMAND EXECU‐ ...


1

@Oli told you why it is probably failing so I'll just explain the sed code: sed -i "s/tk[0-9]*;/tk$company_id;/1i" The s/PATTERN/REPLACEMENT/FLAGS is the substitution operator. It will replace PATTERN with REPLACEMENT. The FLAGS (for example, g in s///g) can modify its behavior. Here, the flags are N (1 in your example) which means "Replace only the Nth ...


1

You're not totally right regarding the meaning the sed options. Let me first explain them then we will understand what your code is doing. Option -i means : instead of displaying the result of the sed processing on the terminal, write it to the file. s/ syntax is s/regexp/replacement/. It means sed will substitute the strings matching the regular ...



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