Tag Info

Hot answers tagged

53

I ran this: strace -o spork.out bash -c "echo 1234 >> some-file" to figure out your question. This is what I found: open("some-file", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3 No file named "some-file" existed in the directory in which I ran the echo command.


42

This is not only done in Bash, it's required by the standard. From the Single Unix Specification: Appended output redirection shall cause the file whose name results from the expansion of word to be opened for output on the designated file descriptor. The file is opened as if the open() function as defined in the System Interfaces volume of POSIX.1-2008 ...


25

Looking in the source, it does use O_APPEND. For bash 4.3.30 in make_cmd.c line 710-713 read: case r_appending_to: /* >>foo */ case r_append_err_and_out: /* &>> filename */ temp->flags = O_APPEND | O_WRONLY | O_CREAT; break;


24

A new install will seldom break your system (unless you do weird stuff like mixing source and binary). If you use precompiled binaries in Ubuntu then you can remove them and not have to worry about breaking your system, because a binary should list what it requires to run and your package manager will list what programs rely on that program for you to ...


17

fork() was the original UNIX system call. It can only be used to create new processes, not threads. Also, it is portable. In Linux, clone() is a new, versatile system call which can be used to create a new thread of execution. Depending on the options passed, the new thread of execution can adhere to the semantics of a UNIX process, a POSIX thread, ...


15

Let's investigate that using strace on a local (non-NFS) filesystem: $ strace -eopen -- bash -c "echo foo >> /tmp/testfile000" 2>&1 | grep /tmp/testfile000 open("/tmp/testfile000", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3 $ strace -eopen -- bash -c "echo foo > /tmp/testfile000" 2>&1 | grep /tmp/testfile000 open("/tmp/testfile000", ...


15

In theory, make uninstall should remove what make install added and your system not accumulate cruft. Problem, of course, is that not all makefiles are created equal. Some may omit the uninstall rule, leaving it to you to figure out what the install rule did. Worse, if install rule overwrote a linked library, dumb uninstall routine may break the ...


12

I would recommend you you use apt-get install to install any package in linux and apt-get remove (package name) or apt-get purge (package name) which will remove not only the main package that you are want to uninstall but all the associated packages or dependencies that were installed during the installation. Now, to keep your system cleaner I'd recommend ...


10

To add Eric's answer (don't have rep to comment), permissions are not stored in file but file's inode (filesystem's pointer to the file's physical location on disk) as metadata along with owner and timestamps. This means that copying file to non-POSIX filesystem like NTFS or FAT will drop the permission and owner data. File owner and group is just a pair of ...


10

The normal way to manage installed applications under Linux is with a package manager. The choice of package managers is one of the main things that differentiate distributions. Ubuntu, like Debian (which it is based on), uses dpkg and APT; most of the time, you only need to interact with one of the interfaces to APT, such as apt-get (command line), aptitude ...


9

Use single quotes to suppress processing of special characters. You could also backslash the $s. For a complex command you are probably better off using a function in any case, which doesn't require any escaping and is easier to read and edit: svnbranch() { svn diff -r $(svn info | grep ^Revision | awk {'print $2'}):HEAD $(svn info | grep ^URL | awk ...


7

Sure, of course, since you can develop portable software that runs on both MacOS and Linux. Be sure to test it on Linux at regular intervals to make sure you haven't unintentionally added something unportable. If you want to use Linux-specific features then you will have more of a hard time. Depending on what it is you do, the program may compile on MacOS ...


7

My question is, which file in /proc gets read by the kernel during the boot up process? This was a question on my LPIC 101 test... Sounds like a trick question. The files in /proc aren't real files on disk (this is why they have a size of 0) and the nodes don't exist until the kernel mounts a procfs file system there and populates it. Procfs and sysfs ...


7

With write: write <user> Some text goes here CTRL-D (eof) Alternative: echo "Some text goes here" | write <user> See man write.


7

You should try to use your package manager (apt-get, aptitude, synaptic, or aptdcon, software-center, mintinstall, ..) if at all possible. Using a make task for installing is very raw, not guaranteed to have an uninstall counterpart and not guaranteed to play well with the rest of the system (It's just a script tied into make's build system -- and unlike a ...


7

Almost every distro has its own choice of package manager, there are several popular-ish ones. pacman, apt, rpm, emerge, ... debian-based distros use apt. The doc looks daunting but it's not actually all that hard to make .debs for local use, just stay on task.


6

1) Download and install Samba: apt-get install samba samba-common 2) Backup samba.conf: cp /etc/samba/smb.conf /etc/samba/smb.conf.bak 3) Edit samba.conf: nano /etc/samba/smb.conf Replace all with and edit it to your wishes: [global] workgroup = arbeitsgruppe server string = %h server (Samba %v) log file = ...


6

The error message you received probably indicates that no file matched the name pattern .swp$. A generally safer way to do what you wrote (because it will handle any file name): find . -name '*.swp' -print0 | xargs -0 rm -i --


6

Try: cat /sys/class/net/eth0/speed I'm not sure what you mean by primary interface. On a host with an IPv4 stack, you could retrieve the interface where the first default route is with: ip route show 0/0 | grep -Pom1 'dev +\K[^ ]+' (assuming GNU grep). So: cat "/sys/class/net/$(ip route show 0/0 | grep -Pom1 'dev +\K[^ ]+')/speed" Not all IPv4 ...


6

why am I getting hangups You aren't getting "hangups" from cat(1) and tail(1), they're just blocking on read. cat(1) waits for input, and prints it as soon as it sees a complete line: $ cat /dev/stdout foo foo bar bar Here I typed fooEnterbarEnterCTRL-D. tail(1) waits for input, and prints it only when it can detect EOF: $ tail /dev/stdout foo bar ...


6

Device files on Unix systems in general are just one way for user programs to access device drivers; there isn't a one-to-one mapping from devices files to physical hardware, and not all hardware has a device file (or even a device driver). The kernel itself doesn't use device files to interact with hardware. As pointed out by lcd047, network cards don't ...


5

You can view if a file called /etc/debian_version exists. $ cat /etc/debian_version wheezy/sid If it exists, you also can see the version of debian. Also distributions like Ubuntu, Linux Mint, and so on, which are based on Debian have that file. Actually most distributions have a release file you can also try and see what comes out: cat /etc/*release


5

Or a variation with find alone e.g.: find . -name "*.swp" -ok rm {} + or just without confirmation (WARNING!): find . -name "*.swp" -delete


5

Those are incomplete reads. It should go away if you add iflag=fullblock. By default, dd will happily accept smaller blocks from a pipe, if there isn't more data readily available. With the iflag, dd will wait until a full block of data has been gathered, or EOF. In regards to data consistency there should be no issue, so you should be getting correct ...


5

Pro tip: There is never really a good reason to run sudo su. To run a command as a different user, use sudo -u username command. If you want a root shell, run sudo -i or sudo -l. If you have activated the root account, you can also run su alone, but sudo su is just not useful. And yes, I know you see it everywhere. That said, sudo has the -E switch which ...


5

You realy should'nt do this. In case you enter your password with just 1 char wrong, everyone who has access to that list/logfile can guess your password. Log who and when someone failed to authenticate. What your trying to achieve is a security risk.


5

Linux kernel maintainers are listed in the MAINTAINERS file in the kernel source code. There's a specific section for memory management: MEMORY MANAGEMENT L: linux-mm@kvack.org W: http://www.linux-mm.org S: Maintained F: include/linux/mm.h F: include/linux/gfp.h F: include/linux/mmzone.h F: include/linux/memory_hotplug.h ...


4

It won't be fast, especially for a large tarball with lots of files, but in bash you can do this: tar -tzf tarball.tgz | while IFS= read -r file; do tar --no-recursion -xzf tarball.tgz -- "$file" gzip -- "$file" done The first tar command extracts the names of the files in the tarball, and passes those names to a while read ... loop. The file ...


4

This was asked recently but it was in the context of local disks. In that situation, there is a good reason to use a partition table on the disk even if you only intend to make it a single big partition spanning the entire disk: documenting the fact that the disk is actually in use, thus preventing accidents. I believe that the situation is different for ...


4

You can use awk and its string comparison operator. ls | awk '$0 < "3_20150415"' In a variable: max=3_20150414 export max ls | LC_ALL=C awk '$0 <= ENVIRON["max"] "z"' concatenating with "z" here makes sure that the comparison is a string comparison, and allows any time on that day since in the C locale, digits sort before z.



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