Tag Info

Hot answers tagged

22

With GNU, FreeBSD or OS/X date (or date implementations that use the system's libc's strftime() where that is the GNU libc), adding hyphen - after % prevents numeric fields from being padded with zeroes: $ date +'%Y%-m%d' 2015120 From man date on a GNU system: By default, date pads numeric fields with zeroes. The following optional flags may ...


8

You must not forget to call ls: alias ls='echo "Hello World!"; ls'


7

Yes, it's the PID of ls: /proc/self This directory refers to the process accessing the /proc file system, and is identical to the /proc directory named by the process ID of the same process. (from man 5 proc) /proc/self is a symbolic link to /proc/PID for the PID of the process that accesses the link, by the magic of the proc filesystem. In your ...


7

Sometimes an alias isn't powerful enough to easily do what you want, so here's a way without using them. In some file that is sourced when your shell starts (e.g. .bashrc), add the following function: ls () { echo "Hello world!" command ls } Unlike an alias, a function can recurse. That's why command ls is used instead of ls; it tells your shell ...


6

advanced cp cp -r /home/username/A/. /usr/lib/B/ This is especially great because it works no matter whether the target directory already exists. shell globbing If there are not too many objects in the directory then you can use shell globbing: mkdir -p /usr/lib/B/ shopt -s dotglob cp -r /home/username/A/* /usr/lib/B/ rsync rsync -a ...


5

Yes, that's the PID of ls. POSIX defined ls as an external command, so anytime you run ls, the shell must create new process and run ls in that process. To do that, the shell will call execve() system call: $ strace ls -l /proc/self execve("/bin/ls", ["ls", "-l", "/proc/self"], [/* 76 vars */]) = 0 You can see, after new process was created, /proc/self ...


4

Quotes (either single or double) around an argument inhibit glob expansion. Your first example passes a Regular Expression as an argument to grep. Your second example contains a glob pattern which the shell itself expands, passing filenames that fit that pattern as arguments to grep.


3

Not the issue of ls. It's how symlinks work. The .. gets you into the parent of the current directory, the directory doesn't know you got to it through a symlink. The shell has to intervene to prevent this behaviour. For the shell builtin cd, there is special handling that doesn't just call chdir but memorizes the full directory path and tries to figure out ...


3

If on a GNU system, from man cp: -T, --no-target-directory treat DEST as a normal file This allows you to write cp -rT /home/username/A/ /usr/lib/B/ to do exactly the right thing.


3

Compare also: echo '.*[s]' file with echo .*[s] file This outputs the arguments as seen by the command. In your first example you pass your grep command exactly two arguments: the pattern and the file. In your second example your shell will handle the first argument and replace it with all the files starting with a dot and ending in "s". Therefore ...


3

> date +'%Y %m %d' | ( read year month day; echo "${year}${month#0}${day}" ) 2015120


2

./ is not a command. It's a directory (current directory). This just means that you run a file ./phpstorm.sh (file named phpstorm.sh that is in the current directory). Every command that you write is first searched in all the directories in $PATH environment variable. This is why, for instance, ls works and you don't have to write /bin/ls. Write echo ...


2

Well, you probably have mail. ;) It talks about your local inbox. Use mail or mutt or from to see your local mails. I'm not sure what mail client is installed per default on OSX, but I would expect to find mail on pretty much any unix system. OSX, at the end, is just another unix and unix is designed to be a multi-user system, i.e. multiple different ...


2

That's typically where you'd use the hold space: ls | sed ' /\.png$/!d; # discard everything but lines ending in .png s///; # remove that .png h; # store on the hold space s/_//g; # remove underscores H; # append (with a newline) to the hold space g; # retrieve that hold space s|\n|/|; # substitute the ...


2

Use wc -l twice and subtract the results. before=$(wc -l < yourfile) sleep 60 after=$(wc -l < yourfile) let dif=after-before echo "$dif" You may also just print the last $dif lines: tail -n$dif yourfile Although more lines could have been appended in the mean time, none of the operations are atomic here. If you want to track incremental changes ...


2

{ tail -c 1 > /dev/null sleep 60 wc -l } < your-file With ksh93: { sleep 60; wc -l; } < your-file <#((EOF)) That opens the file, seeks to the end (in the first one reading and discarding one byte), then sleeps for 60 seconds, and then calls wc -l to count the number of newline characters in between the position we were at 1 minute ago ...


2

Function keys can be interpreted by the window manager or terminal emulator (you'll find that F11, for example, will usually maximize the window) or passed through to the program as VTxxx or ANSI escape sequences. F9 on Linux and Solaris usually sends ESC[20~. Depending on the versions of the software, bash or ksh will interpret this as either 0~ or ~. On ...


2

The way you are doing this, with compressing a .tar file the answer is for sure no. Whatever you use for compressing the .tar file, it doesn't know about the contents of the file, it just sees a binary stream, and whether parts of that stream are uncompressable, or minimally compressible, there is no way this is known. Don't be confused by the options for ...


2

I would say that step 3 (Configuring) has been failed. Didn't you got any error at step 3? (For the third step you need glibc also installed, make sure you have this). Furthermore, why don't you use the package management? Like apt-get install valgrind? Which distro are u using? Kind regards, Arno


2

You have a terminal (or terminal emulator) which understands multibyte encodings (probably UTF-8), but a shell which doesn't. Try setting the environment variable LANG to C.UTF-8. Or run locale -a to find another likely value to try.


2

Tell cp to copy the directory's contents and not the directory itself: sudo cp -r /home/username/A/* /usr/lib/B/


1

Here it is as one command: echo $(( (2147483633-"$(grep -i isrs /proc/zem0 | grep -Eo '[0-9]+$')")/5184000 )) How the simplification was done First consider this pipeline: cat /proc/zem0 |grep -i isrs` This can be simplified to: grep -i isrs /proc/zem0 Thus, the whole of the first command becomes: grep -i isrs /proc/zem0 | grep -Eo '[0-9]+$' The ...


1

The step ./configure normally reads Makefile.in and writes Makefile. Something went wrong in running it. Run it again and read the output looking for errors. If that fails, read config.log where you might find a clue about what went wrong.


1

You might be looking for recordmydesktop. You can get a window id using wmctrl or xwininfo and then use that id: recordmydesktop --windowid <id_of_window> you can use --pause-shortcut to define a key combination for pause/continue.


1

The LZ4 algorithm could be an option. It checks if the beginning of a block is compressible and stores it uncompressed if the ratio is low. This sucessfully prevents compression of already compressed files without the need to specify their names. The overall compression ratio is lower compared to the algorithms you mention. But LZ4 is very fast, on the ...


1

Yea you would be disconnected. Like Celada say "Connecting to the console is the only safe way!". You can try this and if you can't reconnect with ssh, you can go to your console. But if you use the command: ifdown <interface-name> && ifup <interface-name> I think that's gonna be worked (But you gonna be disconnect).


1

I don't know what makes you think F9 returning a tilde is "correct", but if you want a tilde, you should use the tilde key. Function keys are mostly undefined, based on the differences in the client-side hardware you are using, the client-side software you are using, the server-side software you are using, and the server-side hardware you are using.


1

Playing all the music in current directory, was never so easy, same goes for writing images to the disk, single command does the thing. There are such lot more easier ways in our daily chores which would need quite a number of clicks if GUI was used but using commands in the linux comes handy most of the times. for i in *.mp3; do mplayer "$i"; done For a ...


1

You can start with sed 's/\(:[^: ]\+\) \([^(]\)/\1\n\2/g;s/\()\)/\1\n/;s/^ \+//' it should be close enough, and most probably can be simplified and optimized further. The result: eth0 Link encap:Ethernet HWaddr CE:FD:75:DF:A5:6D inet addr:172.16.4.177 Bcast:172.16.5.255 Mask:255.255.254.0 inet6 addr: fe80::adfd:75ef:fedf:v56d/64 Scope:Link UP ...


1

If you add a one (1) after the hyphen (-) it works on Linux and is also portable to HP-UX (and possibly other flavors of UNIX): $ date +'%Y%-1m%d' 2015120



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