Tag Info

New answers tagged

-1

try ls -A. excerpt from the manual "-A, --almost-all do not list implied . and ..")


0

The autojump utility provides a similar mechanism with a Most Heavily Used directory list. It does, however, require the added tedium of typing jSpace but this is compensated by guessing right more often than not. This is the closest to DWIM that I've used to date.


2

With zsh: zmodload zsh/mapfile setopt extendedglob # best in ~/.zshrc for f (Dir/**/(^*DontTouch).txt(N.)) mapfile[$f]=$mapfile[theCommonComment.txt]$mapfile[$f]


1

On GNU/anything, to insert _after_ the first line: find -name '*.txt' ! -name '*thispattern*' ! -name '*thatpattern*' \ -exec sed -si '1r TheLicense.txt' '{}' + to insert a file before, simplest is somewhat slower and a little bit kludgier: find -name '*.txt' ! -name '*thispattern*' ! -name '*thatpattern*' \ -exec sed -si '1{h;s,.*,cat ...


0

This solution uses bash, find,tac and sed. Copy the following script to a file and make the file executable :chmod +x script Then use as follow : ./script <DIR> <HEADERFILE> Where <DIR> The directory containing files ( or directory containing files..) <HEADERFILE> The file to add on top of each file This is the script: ...


4

The most straight forward way I can see to do this is with GNU find, bash and the sponge utility from moreutils: find dir/with/files -name '*.txt' ! -name '*.DontTouch.txt' -print0 | while IFS= read -rd '' file; do echo 'cat path/to/theCommonComment.txt "$file" | sponge "$file"' done As it stands this will just print the cat/sponge commands ...


3

The difference between man and other commands like ls is that latter ones (those not complaining about non-existent directory) don't try to explicitly change there but already stay there. Man also does, but it additionally tries to explicitly change there, too. UNIX directories (as files) aren't deleted immediately when you call unlink(2) or rmdir(2) on ...


1

I would create a file as dummy with the contents that you want to be replaced. So dummy file would look like below. <?php /** * * Copyright (C) MyCompany, Ltd. - All Rights Reserved * Unauthorized copying of this file, via any medium is strictly prohibited * Proprietary and Confidential * * */ After that, I would execute the below ...


3

The following function permits to change to sibling directories (bash function) function sib() { ## sib search sibling directories ## prompt for choice (when two or more directories are found, current dir is removed from choices) ## change to directory after selection local substr=$1 local curdir=$(pwd) local choices=$(find ...


1

This is a repost of my answer to a similar question: The ZIP file format includes a directory (index) at the end of the archive. This directory says where, within the archive each file is located and thus allows for quick, random access, without reading the entire archive. This would appear to pose a problem when attempting to read a ZIP archive through a ...


2

The xrandr command is the one you are looking for. An example usage is: xrandr --output HDMI1 --auto --same-as LVDS1 You can have --left-of, --right-of. Run xrandr on its own to see the different outputs that are available.


1

Use xrand command without args for view your output names and the supported resolutions. Once you have this informations, you can setup a screen like this (this is an example, there is a lot of others options): xrand --output <output> --mode <resolution> --right-of/--left-of <output> You can also just reactivate your screen with: xrand ...


0

Using the wait command $ sleep 10 & [1] 29703 $ wait 29703 && echo hello [1]+ Done sleep 10 hello


4

dc is a very archaic tool and somewhat older than bc. To quote the Wikipedia page: It is one of the oldest Unix utilities, predating even the invention of the C programming language; like other utilities of that vintage, it has a powerful set of features but an extremely terse syntax. The syntax is a reverse polish notation, which basically means that ...


1

A basic difference between the two is that dc uses the reverse Polish notation. It requires explicit commands even in order to produce an output. You might add two integers in bc by saying: bc <<< "2+4" and it would produce 6 on a line by itself. However, in dc you'd need to say: dc <<< "2 4 +p" You can also do much fun stuff using ...


1

dc is a calculator whereas bc is an actual language. See their man pages. dc dc is a reverse-polish desk calculator which supports unlimited precision arithmetic. It also allows you to define and call macros. Normally dc reads from the standard input; if any command arguments are given to it, they are filenames, and dc reads and executes the ...


1

Is there a simpler way to randomize the items in an array with a single command? Assuming you have an array: arr=(4 8 14 18 24 29 32 37 42) You could use printf and shuf to randomize the elements of the array: $ arr=($(printf "%d\n" "${arr[@]}" | shuf)) $ echo "${arr[@]}" 4 37 32 14 24 8 29 42 18 If all that you need is random numbers between ...


3

Since you opened a quotation ' and pressed enter, the shell is wanting you to close the quote. The quote> prompt is simply a visual indication of such. This is so that you can pass multi-line arguments to programs. For example: $ echo 'hi quote> there' hi there Since you typed ls'Enterls'Enter, this is the equivalent to trying to run a command ...


7

You can just pipe the output to shuf. $ seq 100 | shuf Example $ seq 10 | shuf 2 6 4 8 1 3 10 7 9 5 If you want the output to be horizontal then pipe it to paste. $ seq 10 | shuf | paste - -s -d ' ' 1 6 9 3 8 4 10 7 2 5 $ seq 10 | shuf | paste - -s -d ' ' 7 4 6 1 8 3 10 5 9 2 $ seq 10 | shuf | paste - -s -d ' ' 9 8 3 6 1 2 10 4 7 5 Want it with ...


2

printf '%s, ' `seq 1 10 | shuf` You don't even need a for loop. OUTPUT 7, 3, 4, 10, 2, 9, 1, 8, 5, 6, To get them in a shell array you do: ( set -- $(seq 1 10 | shuf) ; printf '%s, ' "$@" ) OUTPUT 5, 9, 7, 2, 4, 3, 6, 1, 10, 8, And then they're in your shell array. If you get them in the shell array, you don't even need printf: ( set -- $(seq 1 ...


1

You may use shuf command to randomize output, e.g %> for x in $(seq 1 10 | shuf); do echo -n "$x "; done; echo 4 10 8 7 1 6 3 5 2 9


1

If you have root access, you can try to do this: # echo b > /proc/sysrq-trigger (that will immediately reboot the system without syncing or unmounting your disks.) Unfortunately, I do not think there is a way to reboot without root privileges.


6

Most basic shell tools are not designed for any very specific purpose at all. Most basic shell tools are designed only to interact with others to achieve your purpose. Or maybe it should be said that most tools do only one very basic thing regardless of how they might be combined to achieve a goal. : >./file That creates an empty file. Or truncates an ...


9

Adrian Frühwirth's answer is right on. I just wanted to add that there is actually a command specifically written to create files: mktemp. NAME mktemp - create a temporary file or directory SYNOPSIS mktemp [OPTION]... [TEMPLATE] DESCRIPTION Create a temporary file or directory, safely, and print its name. TEM‐ PLATE must ...


0

The manual says: -I, --ignore-times don't skip files that match size and time With more details: -I, --ignore-times Normally rsync will skip any files that are already the same size and have the same modification timestamp. This option turns off this "quick check" behavior, causing all files to be updated.


28

I would say because it's hardly ever necessary to create an empty file that you won't fill with content immediately on the command line or in shell scripting. There is absolutely no benefit in creating a file first and then using I/O redirection to write to the file if you can do so in one step. In those cases where you really want to create an empty file ...


1

In order to invoke a command by name, you need to put that symbolic link in one of the directories on the command search path. The environment variable PATH lists the directories in the command search path. The command in your question creates a symbolic link in the current directory, which is not useful. For system-wide commands not provided in a package, ...


0

What I assume is that the path is what identifies the directory. The path to something is how you get there, not the thing itself. The path to your bed may be through your room, but once you are in bed, if someone picks it up and carries it outside, you are no longer in your room.


0

Confirming The current working directory IS based on the inode number, not what you looked up to get there. Since you are using bash, you can use $PWD as follows to cd to the new directory of the same name: cd $PWD To illustrate, I made a dummy deploy command: set -x cd ~/tmp rm -rf code mkdir code echo echo hello from $* > code/run chmod +x code/run ...


0

You can do that using the ANSI control characters: some-command | sed 's/symbol-sequence/^[[0;32;2m symbol-sequence^[[0;0m/' The characters ^[ are not a regular ^ followed by a regular [. It is an unprintable character. You can get it on most terminal by typing Ctrl-v Ctrl-Esc. The second [ is a real [ though. If you prefer full-ascii, here is a ...


3

On most UNIX-like systems, the "current directory" for a process is stored in the kernel as a file descriptor pointing to that directory. The kernel doesn't actually store the path of the current directory: that information is tracked by your shell. A filesystem object (file or directory) is only destroyed for good when all filesystem links to it are gone, ...


0

@Anthon cleared reasons, why it happens As solution you may use alias, as example: alias 1234='PROJECT=`pwd`; cd $PROJECT ; ./run' aliases for bash are keept in ~/.bashrc


20

To me the "cd ../code" is a noop. I'm very interested into hearing why it isn't. Because files and directories are fundamentally filesystem inodes, not names -- this is perhaps an implementation detail specific to the filesystem type, but it is true for all the ext systems, so I'll stick to it here. When a new directory code is created, it is ...


13

Your shell doesn't every time do a cd to the path that it was in during the last command, before executing the next command. You deleted the current directory and created a directory with the same name, which is not the same directory, just something with the same name/path. File browsers like Nautilus and Windows Explorer normally "go up" the directory ...


1

Some commands are built-in; they don't exist on disk, but are executed directly by the shell. These will be documented in the shell's man page or other documentation. Other commands might exist anywhere on disk, but typically will be stored in a directory which appears on the search path. This is represented by the PATH environment variable, whose value is ...


11

The answer is, as so often, "it depends". Usually directories directly under /home are only user home directories. It is entirely possible to put other stuff there too, and it won't harm anything. Whether a user can access a directory under /home, e.g. /home/thisdir, will depend on what permission the directory has. If you grand read and execute ...


-1

Linux process scheduling using nice and renice commands with examples can also be found at http://www.vmexplore.com/tuning-process-scheduling/


1

You can use CopyQ for this. From the website: Clipboard manager with advanced features CopyQ is clipboard manager with searchable and editable history. Supports Linux and Windows. Experimental support for OS X 10.9+. Store text, HTML, images and any other custom format. Advanced command-line interface and scripting. To copy an image ...


4

It sounds like you want something like this (although it's not clear what you mean when distinguishing "iterative command" from "recursive command", since rm -rf is both recursive and iterative): find . -type d -name '.[^.]*' -prune -exec echo rm -rf {} + Once you're happy, remove echo from the option arguments to -exec to remove the listed directories.


3

What is the difference between the ways? from bash manpage: eval [arg ...] The args are read and concatenated together into a single com‐ mand. This command is then read and executed by the shell, and its exit status is returned as the value of eval. If there are no args, or only null ...


0

tcsh set ignoreeof or set ignoreeof=<any value not 1> works


0

As an option you could create wrapper for your script (a .py file): For example, you have a script runme.py so you can create new file runme to wrap the script: #!/usr/bin/env python import runme and then call the runme.py functionality just by invoking runme in the shell. That is useful for multiplatform scripts, cause on Windows platform you can ...


3

You could use \ before the character ? so it is consider as a normal character in the name of the file and not a special character to be interpreted. The command would then be: mv Giko\ Suzo\ San\?e\ -\ Ep1.avi 'Giko Suzo Sane - Ep1.avi' EDIT: following discussion in comments, this line did the trick: mv Giko\ Suzo\ Sa*\ -\ Ep1.avi 'Giko Suzo Sane - ...


4

Auto-complete often fixes problems like this: mv Giko<tab> "Giko Suzo San’e - Ep1.avi"


2

Another difference to the one mentioned is that your shell script runs in a separate shell, therefore any changes to the environment won't propagate out. For example, if you type in your interactive shell test -f foo && file=foo || file=other then your interactive shell will contain a variable file (which you can read with $file) containing foo if ...


6

Yes, && is condition. Command behind will be started only if the previous one returns 0 (ends without an error). On the other hand your script hasn't this control so if eg. wget ends with error it will continue and try to unzip and move nothing.. Onliner for your script is: wget http://something.com ; unzip something ; mv -f something /home/poney/ ...


17

Yes, there is a big difference. && is short-circuiting, so the subsequent command would be executed only if the previous one returned with an exit code of 0. Quoting from the manual: expression1 && expression2 True if both expression1 and expression2 are true. On the other hand, a script containing expression1 expression2 would ...


0

If you have dlocate installed, there's an easy way to list all the commands in an installed package: dlocate -lsbin PACKAGE-NAME With just dpkg, you can list the files in the standard PATH directories (they're almost all executable programs, with very few exceptions): dpkg -L PACKAGE-NAME… | sed -n 's!^\(/s\?bin\|/usr/s\?bin\|/usr/games\)/!!p' | sort -u ...


0

You could use the cups-pdf package as a solution independent from gnome. After installing the package, add the PDF printer using the cups webinterface at http://localhost:631 as described here ('General' as printer manufacturer, CUPS-PDF as driver). For your convenience, change the output directory with the option Out in /etc/cups/cups-pdf.conf to, like, ...


3

1. Use a tool designed for the job. The easiest and probably the most robust way is to install dlocate: sudo apt-get install dlocate You can then run dlocate -lsbin package-name As xplained in man dlocate: -lsbin List full path/filenames of executable files (if any) in package 2. Parse the package database This is a similar approach to @Winny's ...



Top 50 recent answers are included