Linux and Shell Programming, Lecture notes of Computer Applications

Linux and shell programming, MCA, Jawaharlal Nehru Technological University

Typology: Lecture notes

2018/2019
On special offer
30 Points
Discount

Limited-time offer


Uploaded on 09/09/2019

Sujatha1969
Sujatha1969 🇮🇳

4.6

(7)

5 documents

1 / 211

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
LECTURE NOTES
ON
LINUX POROGRAMMING
MCA II YEAR, I SEMESTER
(JNTUA-R17)
Mrs.B.VIJAYA
Asst.Professor
DEPARTMENT OF MASTER OF COMPUTER APPLICATIONS
CHADALAWADA RAMANAMMA ENGINEERING COLLEGE
CHADALAWADA NAGAR, RENIGUNTA ROAD, TIRUPATI (A.P) - 517506
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64
Discount

On special offer

Partial preview of the text

Download Linux and Shell Programming and more Lecture notes Computer Applications in PDF only on Docsity!

LECTURE NOTES

ON

LINUX POROGRAMMING

MCA II YEAR, I SEMESTER

(JNTUA-R 17 )

Mrs.B.VIJAYA

Asst.Professor

DEPARTMENT OF MASTER OF COMPUTER APPLICATIONS

CHADALAWADA RAMANAMMA ENGINEERING COLLEGE

CHADALAWADA NAGAR, RENIGUNTA ROAD, TIRUPATI (A.P) - 517506

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR.

MCA II-I Sem Th 4 (9F00303) LINUX PROGRAMMING UNIT I Linux Utilities-File handling utilities, Security by file permissions, Process utilities, Disk utilities, Networking commands, Filters, Text processing utilities and Backup utilities, sed – scripts, operation, addresses, commands, applications, awk – execution, fields and records, scripts, operation, patterns, actions, functions, using system commands in awk. UNIT II Working with the Bourne again shell(bash): Introduction, shell responsibilities, pipes and input Redirection, output redirection, here documents, running a shell script, the shell as a programming language, shell meta characters, file name substitution, shell variables, command substitution, shell commands, the environment, quoting, test command, control structures, arithmetic in shell, shell script examples, interrupt processing, functions, debugging shell scripts. Linux Files: File Concept, File System Structure,Inodes, File types, The standard I/O (fopen, fclose, fflush, fseek, fgetc, getc, getchar, fputc, putc, putchar, fgets, gets etc.), formatted I/O, stream errors, kernel support for files, System calls, library functions, file descriptors, low level file access - usage of open, creat, read, write, close, lseek, stat family, umask, dup, dup2, fcntl, file and record locking. file and directory management - chmod, chown, links(soft links & hard links - unlink, link, symlink), mkdir, rmdir, chdir, getcwd, Scanning Directories-opendir, readdir, closedir,rewinddir, seekdir, telldir functions. UNIT III Linux Process – Process concept, Kernel support for process, process attributes, process hierarchy,process states,process composition, process control - process creation, waiting for a process, process termination, zombie process,orphan process, system call interface for process management-fork, vfork, exit, wait, waitpid, exec family, system.Signals Interprocess Communication : Introduction to IPC, IPC between processes on a single computer system, IPC between processes on different systems,pipes, FIFOs, Introduction to three types of IPC(Linux)-message queues, semaphores and shared memory. Message Queues. UNI-IV Semaphores-Kernel support for semaphores, Linux APIs for semaphores, file locking with semaphores.

UNIT-I

LINUX UTILITIES

Introduction to Linux Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of Linux is the Linux kernel, an operating system kernel first released 5 October 1991 by Linus Torvalds. Linux was originally developed as a free operating system for Intel x86-based personal computers. It has since been ported to more computer hardware platforms than any other operating system. It is a leading operating system on servers and other big iron systems such as mainframe computers and supercomputers more than 90% of today's 500 fastest supercomputers run some variant of Linux, including the 10 fastest. Linux also runs on embedded systems (devices where the operating system is typically built into the firmware and highly tailored to the system) such as mobile phones, tablet computers, network routers, televisions and video game consoles; the Android system in wide use on mobile devices is built on the Linux kernel. A distribution oriented toward desktop use will typically include the X Window System and an accompanying desktop environment such as GNOME or KDE Plasma. Some such distributions may include a less resource intensive desktop such as LXDE or Xfce for use on older or less powerful computers. A distribution intended to run as a server may omit all graphical environments from the standard install and instead include other software such as the Apache HTTP Server and an SSH server such as OpenSSH. Because Linux is freely redistributable, anyone may create a distribution for any intended use. Applications commonly used with desktop Linux systems include the Mozilla Firefox web browser, the LibreOffice office application suite, and the GIMP image editor.Since the main supporting user space system tools and libraries originated in the GNU Project, initiated in 1983 by Richard Stallman, the Free Software Foundation prefers the name GNU/Linux. History of Unix The Unix operating system was conceived and implemented in 1969 at AT&T's Bell Laboratories in the United States by Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna. It was first released in 1971 and was initially entirely written in assembly language, a common practice at the time. Later, in a key pioneering approach in 1973, Unix was re-written in the programming language C by Dennis Ritchie (with exceptions to the kernel and I/O). The availability of an operating system written in a high-level language allowed easier portability to different computer platforms. Today, Linux systems are used in every domain, from embedded systems to supercomputers, and have secured a place in server installations often using the popular LAMP application stack. Use of Linux distributions in home and enterprise desktops has been growing. They have also gained popularity with various local and national governments. The federal government of Brazil is well known for its support for Linux. News of the Russian

military creating its own Linux distribution has also surfaced, and has come to fruition as the G.H.ost Project. The Indian state of Kerala has gone to the extent of mandating that all state high schools run Linux on their computers. Design A Linux-based system is a modular Unix-like operating system. It derives much of its basic design from principles established in Unix during the 1970s and 1980s. Such a system uses a monolithic kernel, the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are either integrated directly with the kernel or added as modules loaded while the system is running. Separate projects that interface with the kernel provide much of the system's higher- level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is built on top of an implementation of the X Window System. Programming on Linux Most Linux distributions support dozens of programming languages. The original development tools used for building both Linux applications and operating system programs are found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. First released in 2003, the Low Level Virtual Machine project provides an alternative open-source compiler for many languages. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler. BASIC in the form of Visual Basic is supported in such forms as Gambas, FreeBASIC, and XBasic. Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. While not as common, Linux also supports C# (via Mono), Vala, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open- source projects like Kaffe and JikesRVM. Linux Advantages

  1. Low cost: You don’t need to spend time and money to obtain licenses since Linux and much of its software come with the GNU General Public License. You can start to work immediately without worrying that your software may stop working anytime because the free trial version expires. Additionally, there are large repositories from which you can freely download high quality software for almost any task you can think of.
  2. Stability: Linux doesn’t need to be rebooted periodically to maintain performance levels. It doesn’t freeze up or slow down over time due to memory leaks and such. Continuous up-times of hundreds of days (up to a year or more) are not uncommon.
  3. Performance: Linux provides persistent high performance on workstations and on networks. It can handle unusually large numbers of users simultaneously, and can make old computers sufficiently responsive to be useful again.

Linux is just a kernel. All Linux distributions includes GUI system + GNU utilities (such as cp, mv, ls,date, bash etc) + installation & management tools + GNU c/c++ Compilers

  • Editors (vi) + and various applications (such as OpenOffice, Firefox). However, most UNIX operating systems are considered as a complete operating system as everything come from a single source or vendor. As I said earlier Linux is just a kernel and Linux distribution makes it complete usable operating systems by adding various applications. Most UNIX operating systems comes with A-Z programs such as editor, compilers etc. For example HP-UX or Solaris comes with A-Z programs. License and cost Linux is Free (as in beer [freedom]). You can download it from the Internet or redistribute it under GNU licenses. You will see the best community support for Linux. Most UNIX like operating systems are not free (but this is changing fast, for example OpenSolaris UNIX). However, some Linux distributions such as Redhat / Novell provides additional Linux support, consultancy, bug fixing, and training for additional fees. User-Friendly Linux is considered as most user friendly UNIX like operating systems. It makes it easy to install sound card, flash players, and other desktop goodies. However, Apple OS X is most popular UNIX operating system for desktop usage. Security Firewall Software Linux comes with open source netfilter/iptables based firewall tool to protect your server and desktop from the crackers and hackers. UNIX operating systems comes with its own firewall product (for example Solaris UNIX comes with ipfilter based firewall) or you need to purchase a 3rd party software such as Checkpoint UNIX firewall. Backup and Recovery Software UNIX and Linux comes with different set of tools for backing up data to tape and other backup media. However, both of them share some common tools such as tar, dump/restore, and cpio etc. File Systems ▪ Linux by default supports and use ext3 or ext4 file systems. ▪ UNIX comes with various file systems such as jfs, gpfs (AIX), jfs, gpfs (HP-UX), jfs, gpfs (Solaris). System Administration Tools
  1. UNIX comes with its own tools such as SAM on HP-UX.
  2. Suse Linux comes with Yast
  3. Redhat Linux comes with its own gui tools called redhat-config-*. However, editing text config file and typing commands are most popular options for sys admin work under UNIX and Linux. System Startup Scripts Almost every version of UNIX and Linux comes with system initialization script but they are located in different directories:
  4. HP-UX - /sbin/init.d
  5. AIX - /etc/rc.d/init.d
  6. Linux - /etc/init.d

End User Perspective The differences are not that big for the average end user. They will use the same shell (e.g. bash or ksh) and other development tools such as Perl or Eclipse development tool. System Administrator Perspective Again, the differences are not that big for the system administrator. However, you may notice various differences while performing the following operations:

  1. Software installation procedure
  2. Hardware device names
  3. Various admin commands or utilities
  4. Software RAID devices and mirroring
  5. Logical volume management
  6. Package management
  7. Patch management UNIX Operating System Names A few popular names:
  8. HP-UX
  9. IBM AIX
  10. Sun Solairs
  11. Mac OS X 5. IRIX Linux Distribution (Operating System) Names A few popular names:
  12. Redhat Enterprise Linux
  13. Fedora Linux
  14. Debian Linux
  15. Suse Enterprise Linux
  16. Ubuntu Linux Common Things Between Linux & UNIX Both share many common applications such as:
  17. GUI, file, and windows managers (KDE, Gnome)
  18. Shells (ksh, csh, bash)
  19. Various office applications such as OpenOffice.org
  20. Development tools (perl, php, python, GNU c/c++ compilers)
  21. Posix interface FUNDAMENTAL DIFFERENCES BETWEEN LINUX AND WINDOWS #1: Full access vs. no access Having access to the source code is probably the single most significant difference between Linux and Windows. The fact that Linux belongs to the GNU Public License ensures that users (of all sorts) can access (and alter) the code to the very kernel that serves as the foundation of the Linux operating system. You want to peer at the Windows code? Good luck. Unless you are a member of a very select (and elite, to many) group, you will never lay eyes on code making up the Windows operating system.

out and purchase a US Robotics external modem because that was the one modem I knew would work. This is not so much the case now. You can grab a PC (or laptop) and most likely get one or more Linux distributions to install and work nearly 100 percent. But there are still some exceptions. For instance, hibernate/suspend remains a problem with many laptops, although it has come a long way. With Windows, you know that most every piece of hardware will work with the operating system. Of course, there are times (and I have experienced this over and over) when you will wind up spending much of the day searching for the correct drivers for that piece of hardware you no longer have the install disk for. But you can go out and buy that 10-cent Ethernet card and know it’ll work on your machine (so long as you have, or can find, the drivers). You also can rest assured that when you purchase that insanely powerful graphics card, you will probably be able to take full advantage of its power. #5: Command line vs. no command line No matter how far the Linux operating system has come and how amazing the desktop environment becomes, the command line will always be an invaluable tool for administration purposes. Nothing will ever replace my favorite text-based editor, ssh, and any given command-line tool. I can’t imagine administering a Linux machine without the command line. But for the end user — not so much. You could use a Linux machine for years and never touch the command line. Same with Windows. You can still use the command line with Windows, but not nearly to the extent as with Linux. And Microsoft tends to obfuscate the command prompt from users. Without going to Run and entering cmd (or command, or whichever it is these days), the user won’t even know the command-line tool exists. And if a user does get the Windows command line up and running, how useful is it really? #6: Centralized vs. noncentralized application installation The heading for this point might have thrown you for a loop. But let’s think about this for a second. With Linux you have (with nearly every distribution) a centralized location where you can search for, add, or remove software. I’m talking about package management systems, such as Synaptic. With Synaptic, you can open up one tool, search for an application (or group of applications), and install that application without having to do any Web searching (or purchasing). Windows has nothing like this. With Windows, you must know where to find the software you want to install, download the software (or put the CD into your machine), and run setup.exe or install.exe with a simple double-click. For many years, it was thought that installing applications on Windows was far easier than on Linux. And for many years, that thought was right on target. Not so much now. Installation under Linux is simple, painless, and centralized. #7: Flexibility vs. rigidity I always compare Linux (especially the desktop) and Windows to a room where the floor and ceiling are either movable or not. With Linux, you have a room where the floor and ceiling can be raised or lowered, at will, as high or low as you want to make them. With Windows, that floor and ceiling are immovable. You can’t go further than Microsoft has deemed it necessary to go. Take, for instance, the desktop. Unless you are willing to pay for and install a third- party application that can alter the desktop appearance, with Windows you are stuck with

what Microsoft has declared is the ideal desktop for you. With Linux, you can pretty much make your desktop look and feel exactly how you want/need. You can have as much or as little on your desktop as you want. From simple flat Fluxbox to a full-blown 3D Compiz experience, the Linux desktop is as flexible an environment as there is on a computer. #8: Fanboys vs. corporate types I wanted to add this because even though Linux has reached well beyond its school- project roots, Linux users tend to be soapbox-dwelling fanatics who are quick to spout off about why you should be choosing Linux over Windows. I am guilty of this on a daily basis (I try hard to recruit new fanboys/girls), and it’s a badge I wear proudly. Of course, this is seen as less than professional by some. After all, why would something worthy of a corporate environment have or need cheerleaders? Shouldn’t the software sell itself? Because of the open source nature of Linux, it has to make do without the help of the marketing budgets and deep pockets of Microsoft. With that comes the need for fans to help spread the word. And word of mouth is the best friend of Linux. Some see the fanaticism as the same college-level hoorah that keeps Linux in the basements for LUG meetings and science projects. But I beg to differ. Another company, thanks to the phenomenon of a simple music player and phone, has fallen into the same fanboy fanaticism, and yet that company’s image has not been besmirched because of that fanaticism. Windows does not have these same fans. Instead, Windows has a league of paper- certified administrators who believe the hype when they hear the misrepresented market share numbers reassuring them they will be employable until the end of time. #9: Automated vs. nonautomated removable media I remember the days of old when you had to mount your floppy to use it and unmount it to remove it. Well, those times are drawing to a close — but not completely. One issue that plagues new Linux users is how removable media is used. The idea of having to manually “mount” a CD drive to access the contents of a CD is completely foreign to new users. There is a reason this is the way it is. Because Linux has always been a multiuser platform, it was thought that forcing a user to mount a media to use it would keep the user’s files from being overwritten by another user. Think about it: On a multiuser system, if everyone had instant access to a disk that had been inserted, what would stop them from deleting or overwriting a file you had just added to the media? Things have now evolved to the point where Linux subsystems are set up so that you can use a removable device in the same way you use them in Windows. But it’s not the norm. And besides, who doesn’t want to manually edit the /etc/fstab fle? #10: Multilayered run levels vs. a single-layered run level I couldn’t figure out how best to title this point, so I went with a description. What I’m talking about is Linux’ inherent ability to stop at different run levels. With this, you can work from either the command line (run level 3) or the GUI (run level 5). This can really save your socks when X Windows is fubared and you need to figure out the problem. You can do this by booting into run level 3, logging in as root, and finding/fixing the problem. With Windows, you’re lucky to get to a command line via safe mode — and then you may or may not have the tools you need to fix the problem. In Linux, even in run level 3, you can still get and install a tool to help you out (hello apt-get install APPLICATION via the command line). Having different run levels is helpful in another way. Say the machine in question is a

The above cat command will concatenate the two files (file1.txt and file2.txt) and it will display the output in the screen. Some times the output may not fit the monitor screen. In such situation you can print those files in a new file or display the file using less command. cat file1.txt file2.txt | less

  1. To concatenate several files and to transfer the output to another file. cat file1.txt file2.txt > file3.txt In the above example the output is redirected to new file file3.txt. The cat command will create new file file3.txt and store the concatenated output into file3.txt. rm Command: rm linux command is used to remove/delete the file from the directory. SYNTAX: The Syntax is s rm [options..] [file | directory] OPTIONS:
  • f Remove all files in a directory without prompting the user.
  • i Interactive. With this option, rm prompts for confirmation before removing any files.
  • r (or) - R Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally prompted for removal of any write-protected files which the directory contains. EXAMPLE:
  1. To Remove / Delete a file: rm file1.txt Here rm command will remove/delete the file file1.txt.
  2. To delete a directory tree: rm - ir tmp This rm command recursively removes the contents of all subdirectories of the tmp directory, prompting you regarding the removal of each file, and then removes the tmp directory itself.
  3. To remove more files at once rm file1.txt file2.txt rm command removes file1.txt and file2.txt files at the same time. cd Command: cd command is used to change the directory. SYNTAX: The Syntax is

cd [directory | ~ | ./ | ../ | - ] OPTIONS:

  • L Use the physical directory structure.
  • P Forces symbolic links. EXAMPLE:
  1. cd linux-command This command will take you to the sub-directory(linux-command) from its parent directory.
  2. cd .. This will change to the parent-directory from the current working directory/sub- directory.
  3. cd ~ This command will move to the user's home directory which is "/home/username". cp Command: cp command copy files from one location to another. If the destination is an existing file, then the file is overwritten; if the destination is an existing directory, the file is copied into the directory (the directory is not overwritten). SYNTAX: The Syntax is cp [OPTIONS]... SOURCE DEST cp [OPTIONS]... SOURCE... DIRECTORY cp [OPTIONS]... --target-directory=DIRECTORY SOURCE... OPTIONS:
  • a same as - dpR. --backup[=CONTROL] make a backup of each existing destination file
  • b like --backup but does not accept an argument.
  • f if an existing destination file cannot be opened, remove it and try again.
  • p same as --preserve=mode,ownership,timestamps. -- preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps) and security contexts, if possible additional attributes: links, all. --no- preserve=ATTR_LIST don't preserve the specified attribute. --parents append source path to DIRECTORY. EXAMPLE:

7373080 child.gif 7373081 email.gif 7373076 indigo.gif The above command displays filename with inode value. ln Command: ln command is used to create link to a file (or) directory. It helps to provide soft link for desired files. Inode will be different for source and destination. SYNTAX: The Syntax is ln [options] existingfile(or directory)name newfile(or directory)name OPTIONS:

  • f Link files without questioning the user, even if the mode of target forbids writing. This is the default if the standard input is not a terminal.
  • n Does not overwrite existing files.
  • s Used to create soft links. EXAMPLE:
  1. ln - s file1.txt file2.txt Creates a symbolic link to 'file1.txt' with the name of 'file2.txt'. Here inode for 'file1.txt' and 'file2.txt' will be different.
  2. ln - s nimi nimi Creates a symbolic link to 'nimi' with the name of 'nimi1'. mkdir COMMAND: mkdir command is used to create one or more directories. SYNTAX: The Syntax is mkdir [options] directories OPTIONS:
  • m Set the access mode for the new directories.
  • p Create intervening parent directories if they don't exist.
  • v Print help message for each directory created. EXAMPLE:
  1. Create directory: mkdir test The above command is used to create the directory 'test'.
  2. Create directory and set permissions:

mkdir - m 666 test The above command is used to create the directory 'test' and set the read and write permission. rmdir Command: rmdir command is used to delete/remove a directory and its subdirectories. SYNTAX: The Syntax is rmdir [options..] Directory OPTIONS:

  • p Allow users to remove the directory dirname and its parent directories which become empty. EXAMPLE:
  1. To delete/remove a directory rmdir tmp rmdir command will remove/delete the directory tmp if the directory is empty.
  2. To delete a directory tree: rm - ir tmp This command recursively removes the contents of all subdirectories of the tmp directory, prompting you regarding the removal of each file, and then removes the tmp directory itself. mv Command: mv command which is short for move. It is used to move/rename file from one directory to another. mv command is different from cp command as it completely removes the file from the source and moves to the directory specified, where cp command just copies the content from one file to another. SYNTAX: The Syntax is mv [-f] [-i] oldname newname OPTIONS:
  • f This will not prompt before overwriting (equivalent to --reply=yes). mv - f will move the file(s) without prompting even if it is writing over an existing target.
  • i Prompts before overwriting another file. EXAMPLE:
  1. To Rename / Move a file:

hiox india

  1. Compare files ignoring white space: diff - w file1.txt file2.txt This command will compare the file file1.txt with file2.txt ignoring white/blank space and it will produce the following output. 2c < hscripts.com

    HSCRIPTS.com 4d < Hioxindia.com

  2. Compare the files side by side, ignoring white space: diff - by file1.txt file2.txt This command will compare the files ignoring white/blank space, It is easier to differentiate the files. HIOX TEST HIOX TEST hscripts.com | HSCRIPTS.com with friend ship with friend ship Hioxindia.com < The third line(with friend ship) in file2.txt has more blank spaces, but still the - b ignores the blank space and does not show changes in the particular line, - y printout the result side by side.
  3. Compare the files ignoring case. diff - iy file1.txt file2.txt This command will compare the files ignoring case(upper-case and lower-case) and displays the following output. HIOX TEST HIOX TEST hscripts.com HSCRIPTS.com About wc Short for word count, wc displays a count of lines, words, and characters in a file. Syntax wc [-c | - m | - C ] [-l] [-w] [ file ... ]
  • c Count bytes.
  • m Count characters.
  • C Same as - m.
  • l Count lines.
  • w Count words delimited by white space characters or new line characters. Delimiting characters are Extended Unix Code (EUC) characters from any code set defined by iswspace() File Name of file to word count. Examples wc myfile.txt - Displays information about the file myfile.txt. Below is an example of the output. 5 13 57 myfile.txt 5 = Lines 13 = Words 57 = Characters About split Split a file into pieces. Syntax split [-linecount | - l linecount ] [ - a suffixlength ] [file [name] ] split - b n [k | m] [ - a suffixlength ] [ file [name]]
  • linecount | - l linecount Number of lines in each piece. Defaults to 1000 lines.
  • a suffixlength Use suffixlength letters to form the suffix portion of the filenames of the split file. If - a is not specified, the default suffix length is 2. If the sum of the name operand and the suffixlength option-argument would create a filename exceeding NAME_MAX bytes, an error will result; split will exit with a diagnostic message and no files will be created.
  • b n Split a file into pieces n bytes in size.
  • b n k Split a file into pieces n*1024 bytes in size.
  • b n m Split a file into pieces n*1048576 bytes in size. File The path name of the ordinary file to be split. If no input file is given or file is
    • , the standard input will be used. name The prefix to be used for each of the files resulting from the split operation. If no name argument is given, x will be used as the prefix of the output files. The combined length of the basename of prefix and suffixlength cannot exceed NAME_MAX bytes; see OPTIONS. Examples split - b 22 newfile.txt new - would split the file "newfile.txt" into three separate files called newaa, newab and newac each file the size of 22. split - l 300 file.txt new - would split the file "newfile.txt" into files beginning with the name "new" each containing 300 lines of text each About settime and touch Change file access and modification time.